Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

C++11 and Qt 5?



  • I'm trying to use (#include <thread> ) in c++11 with Qt 5 but with no luck. I'm using Mac and this is what I did
    My qmake project
    @QT += core
    QT -= gui

    CONFIG += c++11
    CONFIG -= app_bundle
    TARGET = test
    TEMPLATE = app
    SOURCES += main.cpp@

    My main.cpp

    @#include <thread>
    #include <iostream>

    void foo()
    {
    std::cout << "In foo() \n";
    }

    void bar(int x)
    {
    std::cout << "In bar() \n";
    }

    int main()
    {
    std::thread first(foo);
    std::thread second(bar,0);

    std::cout << "main, foo and bar now execute concurrently ...\n";
    
    first.join();
    second.join();
    
    std::cout << "foo and bar completed.\n";
    return 0;
    

    }
    @

    These errors that I'm getting

    @main.cpp:1:18: error: thread: No such file or directory
    main.cpp:10: warning: unused parameter ‘x’
    main.cpp: In function ‘int main()’:
    main.cpp:17: error: ‘thread’ is not a member of ‘std’
    main.cpp:17: error: expected ;' before ‘first’ main.cpp:18: error: ‘thread’ is not a member of ‘std’ main.cpp:18: error: expected;' before ‘second’
    main.cpp:22: error: ‘first’ was not declared in this scope
    main.cpp:23: error: ‘second’ was not declared in this scope
    make: *** [main.o] Error 1@


  • Lifetime Qt Champion

    Hi,

    You need to provide more information: what version of OS X ? What version of Xcode ? etc.



  • @SGaist,
    Mac OS X Lion 10.7.5
    Xcode Version 4.3.3
    Qt 5.0.1 (64 bit)


  • Lifetime Qt Champion


Log in to reply