Qmessagebox throw excepton
-
wrote on 2 Jul 2013, 12:59 last edited by
Hi, i have a thread. in that i wrote:
QMessageBox::information(0,"ss","ss");
but it has following error:
!http://upload7.ir/images/03962076836726290781.jpg(Error)!
any idea? -
yep...don't use QMessageBox outside of gui thread ;)
open the QMessageBox in a slot in the gui thread and call it with a queued connection signal.Edit. this doesn't even need to be the reason for the crash. Can you run the application in your IDE (in debug mode) and check the crash again?
-
wrote on 2 Jul 2013, 13:53 last edited by
on QMessageBox it throw exception. can you explain more how can i fix that?
-
as i said... create a slot which shows the message box in the gui thread.
Meaning create the slot for example in your main window:@
void MyMainWindow::showInformation(...) //SLOT
{
QMessageBox::information(this, ...);
}
@Then create in your thread class:
@
class MyThread : public QThread
{
public:
MyThread() { ... }signals:
void showInfoBox(...);protected:
virtual void run()
{
....
emit showInfoBox(...);
....
}
}
@and where you create your thread object (assuming in your main window class):
@
MyThread* myThread = new MyThread;
connect(myThread, SIGNAL(showInfoBox(...)), this, SLOT(showInformation(...)), Qt::QueuedConnection);
@ -
wrote on 2 Jul 2013, 14:17 last edited by
thanks. i will try that.
1/5