Why starting a thread from QMainWindow causes C++ Runtime to terminate it?



  • EDIT: I no longer need this solved. QTimer does what I need.

    I am trying to use C++11 threads with Qt.
    I am using Qt Creator 3.4.1 with MinGW 4.9.
    I have "QMAKE_CXXFLAGS += -std=c++11" in my pro file.

    In header file I have included the proper header

    #include <thread>
    

    and defined a public function to be used as a thread

    void searchTimer();
    

    In source file I start the thread with

    std::thread delayTimer(&AGEMainWindow::searchTimer, this);
    

    and the thread function looks like this

    void AGEMainWindow::searchTimer()
    {
        while(delayTime > 0)
        {
            delayTime -= DELAYINTERVAL;
            std::this_thread::sleep_for(std::chrono::milliseconds(DELAYINTERVAL));
        }
        emit timeToSearch();
    }
    

    Now that I have solved compiler errors, the program force quits whenever the thread gets launched. C++ Runtime Library closes it.

    Is starting threads banned in Qt derived classes?


  • Moderators

    I have added markdown tags for your code sections.


  • Moderators

    Hi,
    I dont know if this makes a difference here, but I think the recommended way to activate C++11 support is to use "CONFIG += c++11" instead of "QMAKE_CXXFLAGS += -std=c++11".



  • Using "CONFIG += c++11" in pro file doesn't change the error messages.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.