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. The true meaning of the warning for QProcess::waitForFinished

The true meaning of the warning for QProcess::waitForFinished

Scheduled Pinned Locked Moved Solved General and Desktop
qprocesswaitforfinishedfreezedocumentgui
10 Posts 5 Posters 3.3k 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.
  • S Offline
    S Offline
    Shinichiro
    wrote on last edited by
    #1

    Hi, all.

    I am using Qt 5.6.3 with vs2013 x64 and am using QProcess::waitForFinished function in a slot function on GUI application.

    Last week, I have watched infinite freeze on my application on Windows 10 once.
    I have tried to launch "Task Manager" with CTRL+ALT+DELETE however there was no response on Windows also.
    Only the mouse cursor (WAITING - ROUNDED - CURSOR) could move.
    That's why I am re-checking the document.

    In the document, there is a warning message that said "Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze." however I could not understand the true meaning because of the word "freeze".
    https://doc.qt.io/qt-5/qprocess.html#waitForFinished

    If the meaning is "Infinite freeze", I can't use the function for my internal design. Because the implementation is wrong.
    If the meaning is "a few milliseconds or until finished", I can use the function for my internal design. Because it's just a behavior of the function.

    If you know the true meaning, please let me know.

    Shin

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The meaning is: until the process finishes. Which might go from a few millisecond to infinite if the application called through QProcess doesn't end.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      6
      • S Offline
        S Offline
        Shinichiro
        wrote on last edited by
        #3

        Hi SGaist-san,

        Thank you for your clear explanation.
        I understood that using waitForFinished in the slot function is not a wrong implementation.

        Thank you for your quick reply.

        Shin

        aha_1980A 1 Reply Last reply
        0
        • S Shinichiro

          Hi SGaist-san,

          Thank you for your clear explanation.
          I understood that using waitForFinished in the slot function is not a wrong implementation.

          Thank you for your quick reply.

          Shin

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Shinichiro said in The true meaning of the warning for QProcess::waitForFinished:

          I understood that using waitForFinished in the slot function is not a wrong implementation.

          Just to make it clear for the future reader: waitForFinished() should not be used in a Slot. It should only be used in a separate thread,where you don't use Signals&Slots.

          Regards

          Qt has to stay free or it will die.

          1 Reply Last reply
          6
          • S Offline
            S Offline
            Shinichiro
            wrote on last edited by
            #5

            Hi, aha_1980-san,

            Thank you for pointing out.
            Okay, we can't use waitForFinished() in a slot function, however why we can't use it in a slot?
            The function has an argument for the time out, so the function will not be in a finite loop, right?
            I think I should understand the internal design of the GUI thread more to have a true understanding.

            Regards,
            Shin

            jsulmJ 1 Reply Last reply
            0
            • S Shinichiro

              Hi, aha_1980-san,

              Thank you for pointing out.
              Okay, we can't use waitForFinished() in a slot function, however why we can't use it in a slot?
              The function has an argument for the time out, so the function will not be in a finite loop, right?
              I think I should understand the internal design of the GUI thread more to have a true understanding.

              Regards,
              Shin

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Shinichiro What is the point to use signals/slots and waitFor*() functions at the same time? If you call waitForFinished() in a slot it will block the slot until it is finished or times out - until then the thread where your slot is executed will be blocked (if this thread is UI thread your UI will be blocked). The purpose of signals/slots IS to avoid blocking the event loop, so if you already use them why do you need waitForFinished?

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

              S 1 Reply Last reply
              5
              • jsulmJ jsulm

                @Shinichiro What is the point to use signals/slots and waitFor*() functions at the same time? If you call waitForFinished() in a slot it will block the slot until it is finished or times out - until then the thread where your slot is executed will be blocked (if this thread is UI thread your UI will be blocked). The purpose of signals/slots IS to avoid blocking the event loop, so if you already use them why do you need waitForFinished?

                S Offline
                S Offline
                Shinichiro
                wrote on last edited by
                #7

                @jsulm Hi, I was re-using an instance of QProcess in a class for the next processing. so I was using waitForFinished to wait for the previous task to end. That's why I was using the interface. What's the better implementation for that?

                aha_1980A JonBJ 2 Replies Last reply
                0
                • S Shinichiro

                  @jsulm Hi, I was re-using an instance of QProcess in a class for the next processing. so I was using waitForFinished to wait for the previous task to end. That's why I was using the interface. What's the better implementation for that?

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Shinichiro said in The true meaning of the warning for QProcess::waitForFinished:

                  What's the better implementation for that?

                  Well, connect a slot to the finished() signal.

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  5
                  • S Shinichiro

                    @jsulm Hi, I was re-using an instance of QProcess in a class for the next processing. so I was using waitForFinished to wait for the previous task to end. That's why I was using the interface. What's the better implementation for that?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #9

                    @Shinichiro
                    What @aha_1980, @jsulm are trying to guide you towards is: instead of writing your code to wait for things to happen (QProcess finishing) and then doing something next, write it so there is no waiting and instead do your "something next" when a signal arrives to tell you to proceed. That way your GUI does not "block"/"freeze".

                    1 Reply Last reply
                    4
                    • S Offline
                      S Offline
                      Shinichiro
                      wrote on last edited by
                      #10

                      Hi, Thank you for your reply.
                      I totally changed my implementation using the signal and slots.
                      Thank you so much again.

                      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