Results 1 to 2 of 2

Thread: QEventLoop in QApplication

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QEventLoop in QApplication

    Hi,

    A Thread emits a signal and the slot is in the mainthread. The slot's widget has a QEventLoop as Member. Is it ok to call loop.exec() in the slot.
    If I don't call this, the slot returns and the Thread continue, because of BlockingQueuedConnection. But the user should have some time to decide something.

    If the user has decided the I call loop.quit();

    It seems to work, but is this ok. What are the cons?

    thank u

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QEventLoop in QApplication

    The short answer is there is no need to use eventloop just to make a 'false' block in your code. You could just use signals and slots and refactor your thread code. What you have done is block a thread from potentially doing more work. If that thread *truly* can't do any more work, then I don't think it is doing any harm.


    thread code (what you have):
    Qt Code:
    1. void thread::do_something()
    2. {
    3.  
    4. do_x();
    5.  
    6. emit some_signal(); // this is your blocking queued connection
    7.  
    8. do_some_more_stuff();
    9. }
    To copy to clipboard, switch view to plain text mode 

    to this:
    Qt Code:
    1. void thread::do_something_part1()
    2. {
    3. do_x();
    4. emit some_signal();
    5. }
    6.  
    7. void thread::do_something_part2() // this is a slot. connect it to a signal that is sent when user has 'decided something'
    8. {
    9. do_some_more_stuff();
    10. }
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QThread and QEventLoop - Idle Processing
    By kloffy in forum Newbie
    Replies: 14
    Last Post: 28th April 2011, 11:41
  2. QTest and QEventLoop inside a library
    By MementoMori in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2011, 15:38
  3. How to use QEventLoop?
    By MorrisLiang in forum Newbie
    Replies: 3
    Last Post: 13th May 2010, 16:23
  4. qprocess or qeventloop
    By knishaq in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2009, 10:14
  5. static QEventLoop strange behavior
    By SABROG in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 12:04

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.