How to use pthread on Qt Creator

I want to execute a following code.

#include <iostream>
#include <thread>

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

int main()
    std::thread t(output);

    return 0;

I can't execute it.

Qt Creator outputs terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted

However I can execute on the terminal using the option of -pthread. Could you tell me how to use the option of -pthread in Qt Creator?

My developing environment is Ubuntu(12.04), g++4.6.3, Qt Creator(2.4.1).

Thank you.


You also need to link against -pthread. If you use g++ main.cpp -std=c++0x -pthread you are doing all that in one step, so it works correctly. To make Qt do the correct things, add the following to your project file:

QMAKE_CXXFLAGS += -std=c++0x -pthread 
LIBS += -pthread

This works for me:


# Input
SOURCES += test.cpp

QMAKE_CXXFLAGS += -std=gnu++0x -pthread
QMAKE_CFLAGS += -std=gnu++0x -pthread

Your example compiles and executes correctly with the above .pro file on my system.

Try save your example as test.cpp, and the above as in same directory. Then type:

$ qmake
$ make
$ ./project
Hello World

Add your command line arguments here:

Need Your Help

Unable to cast TEXT to XML in SQL Server

sql-server xml sql-server-2005

Basically I have a column named XML that is of type TEXT; this cannot be changed for other reason, but I was wondering how I could cast it to XML.

How to open settings app programmatically?

swift application-settings ios8.3

I'm using swift with ios 8.3. I want to open settings app from my application. I know that using the code