Results 1 to 6 of 6

Thread: calling QMessageBox from a worker thread

  1. #1
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default calling QMessageBox from a worker thread

    I am emitting a signal from a worker thread and connecting it to a slot in GUI thread of MainWindow.
    In the slot I am invoking a QMessageBox and displaying some error message.
    Now I want the worker thread to stop working until I click OK on the QMessageBox.
    Here is how I am doing it:

    //worker thread
    Qt Code:
    1. emit CameraDisconnectSignal("no camera present");
    To copy to clipboard, switch view to plain text mode 
    //GUI thread
    Qt Code:
    1. void MainWindow::CameraDisconnectSlot(QString q)
    2. {
    3. QMessageBox messageBox;
    4. messageBox.critical(0,"Error",q);
    5. messageBox.setFixedSize(500,200);
    6. }
    To copy to clipboard, switch view to plain text mode 

    First of all I am not able to get any MessageBox and secondly I want to stop worker thread till the user clicks OK on GUI thread.
    How can I acheive this??

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: calling QMessageBox from a worker thread

    First of all You don't show message box. Add this line :
    Qt Code:
    1. messageBox.exec();
    To copy to clipboard, switch view to plain text mode 
    Second : read about QObject::connect and especially about third parameter.

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

    prkhr4u (3rd March 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: calling QMessageBox from a worker thread

    And you probably want to use one of the static helper methods of QMessageBox, e.g.

    Qt Code:
    1. QMessageBox::critical(this, "Error", q);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    prkhr4u (3rd March 2014)

  6. #4
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: calling QMessageBox from a worker thread

    Thanks to both of you,I am able to get MessageBox now.
    But I am still unable to stop the thread processing on displaying QMessageBox and resuming it on its OK button click.
    how to achieve that?

  7. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: calling QMessageBox from a worker thread

    Did You read doc for QObject::connect method ?

  8. The following user says thank you to Lesiok for this useful post:

    prkhr4u (4th March 2014)

  9. #6
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: calling QMessageBox from a worker thread

    thank you @Lesiok,I didn't get it in the first time,but Qt::BlockingQueuedConnection did the job for me.

Similar Threads

  1. Replies: 4
    Last Post: 17th October 2013, 11:12
  2. Replies: 3
    Last Post: 20th September 2011, 20:13
  3. Worker thread
    By doggrant in forum Newbie
    Replies: 4
    Last Post: 3rd November 2009, 15:49
  4. Worker thread problem
    By hkvm in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2009, 20:12
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

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.