How to use pthread on Qt Creator

前端 未结 3 1745
囚心锁ツ
囚心锁ツ 2020-12-30 05:33

I want to execute a following code.

#include 
#include 

void output() {
    std::cout << \"Hello World\" << std::e         


        
相关标签:
3条回答
  • 2020-12-30 06:05

    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
    
    0 讨论(0)
  • 2020-12-30 06:16

    This works for me:

    TEMPLATE = app
    TARGET = 
    DEPENDPATH += .
    INCLUDEPATH += .
    
    # 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 project.pro in same directory. Then type:

    $ qmake
    $ make
    $ ./project
    Hello World
    
    0 讨论(0)
  • 2020-12-30 06:23

    Add your command line arguments here: http://doc.qt.nokia.com/qtcreator-2.4/creator-run-settings.html

    0 讨论(0)
提交回复
热议问题