【问题标题】:Qt application with multiple threads具有多线程的 Qt 应用程序
【发布时间】:2013-06-28 17:51:17
【问题描述】:

我有一个 QT 应用程序。

我有一个线程(例如 thread1)显示我的主窗口(因此这与主线程不同)。

我也有自己的线程(例如 thread2)必须通知 thread1 更新我的 GUI。 有一种快速的方法可以做到这一点吗? 例如:thread2可能决定更新图像:因此,他应通知thread1执行changeImage()方法。

如果我直接从 thread2 运行此方法,我的应用程序将会崩溃。 我必须使用 pthread。

【问题讨论】:

    标签: c++ qt delegates pthreads


    【解决方案1】:

    只有主线程应该更新 GUI(由于图形系统的限制)。

    但是,Qt 增强了线程支持,允许跨线程的信号槽连接。事实上,其他线程必须使用信号(emit my_signal() 参见http://qt-project.org/doc/qt-4.8/signalsandslots.html)或使用QCoreApplication::postEventhttp://qt-project.org/doc/qt-4.8/qcoreapplication.html#postEvent-2)通知主线程

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 2015-06-28
      • 2013-09-16
      • 1970-01-01
      相关资源
      最近更新 更多