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. QThread (occasionally) won't start
Qt 6.11 is out! See what's new in the release blog

QThread (occasionally) won't start

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 6.3k Views 1 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.
  • L Offline
    L Offline
    leonidwang
    wrote on last edited by
    #1

    I have a class which inherits QThread, and I always new a object of that class and call the start() method when initialize my program.

    Then I use a python script to star/stop my program over and over, for thousands of times.
    Occasionally, the QThread won't start. Actually, only for once, out of about 3000 times, the QThread failed to launch.

    What's the possible reason? And how do I make sure QThread is started?(since start() is a void function)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      Hard to say without having code details. However I will digg into some run-time conditions, e.g., opening files or memory consumption that could cause your thread-creation-cycle to fail on some iterations.

      Now, knowing that your thread is started also depends on what you are doing. I would use the "started":http://doc.qt.nokia.com/latest/qthread.html#started signal to get informed that the thread is started, and maybe I will log to a log file such event.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        You could ask QThread for the state:

        "isRunning":http://doc.qt.nokia.com/4.7/qthread.html#isRunning

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leonidwang
          wrote on last edited by
          #4

          Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            So, I don'i know why it happens in your special case, but sometimes you can hit OS bounds. Perhaps, there are too many threads running in paralell

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #6

              [quote author="leonidwang" date="1319448574"]Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.[/quote]

              If you are not able to see which threads are started, how can you discriminate which are not started? The idea was to get info to understand what threads are running so to get the conditions under which the other are not started.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                leonidwang
                wrote on last edited by
                #7

                I just put some logs in that thread, and my script collects those logs, that's how I know it is not launched.

                I give up finding out the "reason", anyhow, it is a low-probability event. I'm now querying the thread status and restart it if it is not running.

                [quote author="fluca1978" date="1319456844"]
                [quote author="leonidwang" date="1319448574"]Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.[/quote]

                If you are not able to see which threads are started, how can you discriminate which are not started? The idea was to get info to understand what threads are running so to get the conditions under which the other are not started.[/quote]

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fluca1978
                  wrote on last edited by
                  #8

                  Ok, you find a solution that is fine for you aim(s).
                  The only doubt I have is about the low-probability event: may be this probability raises when deployed to another architecture? Just think about it.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    leonidwang
                    wrote on last edited by
                    #9

                    [quote author="fluca1978" date="1319528580"]Ok, you find a solution that is fine for you aim(s).
                    The only doubt I have is about the low-probability event: may be this probability raises when deployed to another architecture? Just think about it.[/quote]

                    But that's some problem out of Qt's scope.

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fluca1978
                      wrote on last edited by
                      #10

                      [quote author="leonidwang" date="1319600202"]
                      But that's some problem out of Qt's scope.
                      [/quote]

                      Of course, but it is in the scope of your application. I was just suggesting you to investigate more...

                      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