开发者

Display a QMessageBox from a QThread

开发者 https://www.devze.com 2023-01-27 03:22 出处:网络
I want to display a message box from a separate thread, however, I get this error: QThread: Destroyed while thread is still running

I want to display a message box from a separate thread, however, I get this error:

QThread: Destroyed while thread is still running

Can anyone explain h开发者_JAVA百科ow to display a message box from a thread?


Emit a signal. Since you cannot do UI stuff in a Qthread, instead send your message as an argument of your signal.

signal decalaration in your qthread:

signals:
  void write2SysStatus(QString theMessage);

emitting the signal from the qthread:

emit write2SysStatus("Some status");

slot declaration/definition in QMainWindow:

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

connecting of the slot and signal:

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

精彩评论

暂无评论...
验证码 换一张
取 消