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. Problem for While(true) in QT QThread Run function

Problem for While(true) in QT QThread Run function

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.9k Views
  • 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.
  • tony.dacunziT Offline
    tony.dacunziT Offline
    tony.dacunzi
    wrote on last edited by kshegunov
    #1

    Hi,

    All,

    I created one thread, and the run function looks like below:

    void Compass_Message_Handler::run()
    {
        this->handleMessage();
    
        return;
    }
    
    void Compass_Message_Handler::handleMessage()
    {
        while(true)
        {
            if(m_canHandleNxtMsg)//line A
            {
                ////////////////////////////////////
    /////////////////////////////////////////////////
            }
        }
    }
    

    I set a break point at line A. but i find that after several execution, i need to wait for 3 to 5 seconds for the while to run again to the break point line A.

    Do you know why, is it because multi thread and the cpu need to run other thread??????

    [Fixed code formatting ~kshegunov]

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      welcome to the forum. I don't see any issue with your code. Do you see the same behaviour when you run the above program without break point ? What are you doing inside the if condition ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • tony.dacunziT Offline
        tony.dacunziT Offline
        tony.dacunzi
        wrote on last edited by
        #3

        Hi,

        Dheerendra,

        Thanks for your answer, i still not check if i run not in debug mode.

        I will check it ,thanks.

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @dheerendra Asked what you are doing inside that if() condition. Is it something long lasting?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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