如何在Qt Creator上使用pthread

hiz*_*izz 14 c++ qt qt-creator c++11

我想执行以下代码.

#include <iostream>
#include <thread>

void output() {
    std::cout << "Hello World" << std::endl;
}

int main()
{
    std::thread t(output);
    t.join();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我无法执行它.

抛出'std :: system_error'的实例后调用Qt Creator输出终止what():不允许操作

但是我可以使用-pthread选项在终端上执行.你能告诉我如何在Qt Creator中使用-pthread选项吗?

我的开发环境是Ubuntu(12.04),g ++ 4.6.3,Qt Creator(2.4.1).

谢谢.

inf*_*inf 27

你还需要链接-pthread.如果您使用,g++ main.cpp -std=c++0x -pthread您只需一步即可完成所有操作,因此它可以正常工作.要使Qt执行正确的操作,请将以下内容添加到项目文件中:

QMAKE_CXXFLAGS += -std=c++0x -pthread 
LIBS += -pthread
Run Code Online (Sandbox Code Playgroud)