从 QThread 显示 QMessageBox

发布于 2024-10-05 01:52:22 字数 126 浏览 0 评论 0 原文

我想从单独的线程显示消息框,但是,我收到此错误:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

四叶草在未来唯美盛开 2024-10-12 01:52:22

发出信号。由于您无法在 Qthread 中执行 UI 操作,因此请将消息作为信号的参数发送。

qthread 中的信号声明:

signals:
  void write2SysStatus(QString theMessage);

从 qthread 发出信号:

emit write2SysStatus("Some status");

QMainWindow 中的槽声明/定义:

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

槽和信号的连接:

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

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)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文