Show QMessageBox from QThread

I want to display a message box from a separate thread. Here is what I tried:

http://programmingexamples.net/index.php?title=Qt/Widgets/MessageBoxFromThread

However, I get this error: QThread: Destroyed while the thread is still running

Can someone explain how to display a message box from a stream? (or even better, fix this example :)?)

Thank,

David

+3
source share
1 answer

easy. Release a signal. Since you cannot do gui things in qthread, just send your message as an argument to your signal

signal decalation in your qthread:

 signals:
 void write2SysStatus( QString theMessage );

qthread signal emission:

 emit write2SysStatus(msgCatMap['F']+tr("Failed to start logging this mission data because index is invalid: %1 (1 based)").arg(iMsn+1));

Slot declaration / definition in QMainWindow:

public slots:
void eWriteLine ( QString theMessage ){
     //this is where you use you message box.
}

slot and signal connection:

 connect(pFPSengine, SIGNAL(write2SysStatus(QString)), this,SLOT(eWriteLine(QString)));
+3

Source: https://habr.com/ru/post/1777351/


All Articles