Results 1 to 3 of 3

Thread: How to control the events of the main event loop of Qcoreapplication

  1. #1
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default How to control the events of the main event loop of Qcoreapplication

    I use a Qcoreapplication in the main function of a program. I have a sequence of communicating nodes which is read from a file (line by line). At each line, I call sendHello(src,dst). A simple description of the code is as follows:

    file format:
    node1 node2
    node3 node4
    node5 node6

    Qt Code:
    1. int main()
    2. {
    3. Qcoreapplication app;
    4. readfromfile();
    5. app.exec()
    6. }
    7. readfromfile()
    8. {
    9. while(!eof())
    10. sendhello(src,dst),
    11. }
    12. sendHello(src,dst)
    13. {
    14. // Here exchange different messages (more events)
    15. sendmsg2(dst,src)
    16. sendmsg3(src,dst)
    17. }
    To copy to clipboard, switch view to plain text mode 

    Calling each of this sendHello() by each pair, initiates different exchange of information (different events). I found out that the main loop goes from line to line (from pair to pair) and performs the sendHello for each pair sequentially.

    Results I get:

    sendHello(node1,node2)
    sendHello(node3,node4)
    sendmsg2(node2,node1)
    sendmsg3(node1,node2)
    sendmsg2(node4,node3)
    sendmsg3(node2,node4)

    I need to execute the events that are contained in each sendHello (sendmsg2 and sendmsg3) before moving to next lines (pairs). I tried to understand how to control the events of the main event loop, and how the middle events are scheduled but I did not.

    Results I need:

    sendHello(node1,node2)
    sendmsg2(node2,node1)
    sendmsg3(node1,node2)

    sendHello(node3,node4)
    sendmsg2(node4,node3)
    sendmsg3(node2,node4)

    I tried processevents( all events) but it`s not working as required. Don`t know why ?

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to control the events of the main event loop of Qcoreapplication

    You need to start the event loop before you start reading the nodes. Moreover you can't read the nodes in a while loop because you will block the event loop. You can use QTimer::singleShot() with a 0 timeout to schedule execution of a slot without blocking events. You can read more about similar approaches in the article on [wiki]Keeping the GUI Responsive[/wiki].
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Abdu (18th February 2011)

  4. #3
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to control the events of the main event loop of Qcoreapplication

    Thank you so much , the article you provided me is very useful and I could solve the problem. Before any long operation , I created an event loop, and the event loop starts execution till it gets a signal (timer with 0 time out) that this long operation is finished.

Similar Threads

  1. Replies: 3
    Last Post: 10th June 2010, 08:35
  2. Replies: 10
    Last Post: 15th January 2010, 14:35
  3. How to log returning control back to the main event loop?
    By piotr.dobrogost in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2009, 09:57
  4. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10
  5. How to bind Qt3 and Qt4 main event loop.
    By Opilki_Inside in forum Qt Programming
    Replies: 7
    Last Post: 10th May 2006, 08:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.