Results 1 to 5 of 5

Thread: QMessageBox.exec() does not block Producer-Consumer signal loop

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default QMessageBox.exec() does not block Producer-Consumer signal loop

    Hi!,
    I have a singlethreaded application which performs some longer task. The task is devided in to small portions and accomplished by Producer-Consumer, Qt::QueuedConnection, signal-slot loop. Everthing works well, gui is responsive.
    I have a 'Stop' button in the gui. In its 'onClick' event handler i am displaying a confirmation message with use of QMessageBox::exec() function.

    Unfortunately i am facing the following problem:
    When the confirmation message is displayed, sometimes the Producer-Consumer loop is blocked and sometimes it proceeds unaffected.
    I would like the modal confirmation box to block the execution of the Producer-Consumer loop.

    I have read that exec() runs its own event loop and this would explain why Producer-Consumer loop proceeds. However, i am confused with the fact that sometimes it is blocked. And still.. i would like to block this loop somehow.

    Any ideas?
    best regards.
    Last edited by airproject; 30th August 2012 at 11:48.

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

    Default Re: QMessageBox.exec() does not block Producer-Consumer signal loop

    exec() makes another event loop - but you can think of this as another version of the gui event loop.

    I dont think it will be interfering with the running of other threads, and I think it should not be halting the execution of slots in the gui thread.

    If you want to be able to block your producer/consumer, I suggest looking at something like this:
    Qt Code:
    1. void
    2. myclass::slot_block()
    3. {
    4. QEventLoop eventLoop;
    5. connect(this, SIGNAL(continue()), &eventLoop, SLOT(quit()));
    6. eventLoop.exec(); // will process signals/slots, but myclass
    7. // will not otherwise execute any more code until the loop is exited
    8. }
    9.  
    10. void
    11. myclass::slot_continue()
    12. {
    13. emit continue();
    14. }
    To copy to clipboard, switch view to plain text mode 
    ie you need to implement two slots and a signal.
    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.

  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMessageBox.exec() does not block Producer-Consumer signal loop

    Thank you for the reply.
    If i understand you well:
    - QMessageBox::exec() - executes an event loop which processes the GUI thread signals (processes Producer-Consumer, filters out only widget signals?)
    - creating new QEventLoop and running it will be processing utterly new event loop separated form GUI thred with Producer-Consumer signals. This loop will engage application processing untill i quit() it.

    I guess Displaying QMessageBox should be accomplished with some other method (open(), show()) than exec().

    I will do some trials.. and still wonder why sometimes the GUI thread event loop is blocked by exec() and sometimes no:/

    Best regards.

Similar Threads

  1. Any Qt code/example for producer consumer pattern?
    By Sheng in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2009, 21:11
  2. Replies: 16
    Last Post: 28th October 2008, 22:00
  3. Speed up Producer Consumer Threads
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 29th February 2008, 18:38
  4. Producer Consumer...
    By Shuchi Agrawal in forum Newbie
    Replies: 1
    Last Post: 16th February 2007, 09:45
  5. Producer Consumer
    By ^NyAw^ in forum Qt Programming
    Replies: 16
    Last Post: 17th November 2006, 19:53

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.