Display a QMessageBox from a QThread

孤街醉人 提交于 2019-12-10 17:35:39

问题


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 how to display a message box from a thread?


回答1:


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)));


来源:https://stackoverflow.com/questions/4299493/display-a-qmessagebox-from-a-qthread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!