PDA

View Full Version : calling QMessageBox from a worker thread



prkhr4u
28th February 2014, 12:11
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

emit CameraDisconnectSignal("no camera present");
//GUI thread

void MainWindow::CameraDisconnectSlot(QString q)
{
QMessageBox messageBox;
messageBox.critical(0,"Error",q);
messageBox.setFixedSize(500,200);
}

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??

Lesiok
28th February 2014, 12:53
First of all You don't show message box. Add this line :

messageBox.exec();
Second : read about QObject::connect and especially about third parameter.

anda_skoa
28th February 2014, 16:05
And you probably want to use one of the static helper methods of QMessageBox, e.g.



QMessageBox::critical(this, "Error", q);


Cheers,
_

prkhr4u
3rd March 2014, 06:29
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?

Lesiok
3rd March 2014, 08:32
Did You read doc for QObject::connect method ?

prkhr4u
4th March 2014, 02:53
thank you @Lesiok,I didn't get it in the first time,but Qt::BlockingQueuedConnection did the job for me.