Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why starting a thread from QMainWindow causes C++ Runtime to terminate it?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 957 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tapsa
    wrote on last edited by Tapsa
    #1

    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?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      I have added markdown tags for your code sections.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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".

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tapsa
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved