【问题标题】:QT + boost-thread not workingQT + boost-thread 不工作
【发布时间】:2011-07-26 02:34:54
【问题描述】:

我正在使用 Qt 和 boost 编写代码。

我知道 qt 窗口需要在主线程中启动,所以,我正在尝试使用 boost(不是 QThread)在另一个线程中运行一些代码。

问题是,如果我在不启动 qt 窗口的情况下运行我的代码,它工作得非常好,但是,如果我调用 app.exec(),另一个线程(boost 线程)将停止工作。不知道怎么回事,有线索吗?

QApplication app(argc, argv);
QMainWindow window;

//creating a separated thread and starting up
boost::thread thr1( boost::bind( &X::x, &a ) );

//if we join, it works
//thr1.joing()

//but if I run the following lines, my thr1 freezes
window.show();
app.exec();

【问题讨论】:

  • 如何链接 boost 线程?我知道如果您静态链接,Windows 上会出现一些问题。
  • 我正在使用 cmake 进行链接,在我的 CMakeLists.txt 中有 TARGET_LINK_LIBRARIES(project ${Boost_LIBRARIES}) 如果我不启动 qt =/,它就可以工作

标签: qt boost-thread


【解决方案1】:

问题在于我的 boost 实现。我修复了重新编译它

【讨论】:

    猜你喜欢
    • 2012-09-16
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 2011-07-23
    • 2012-03-18
    • 2020-12-21
    • 1970-01-01
    • 2017-02-20
    相关资源
    最近更新 更多