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. WaitForFinished() fires early
QtWS25 Last Chance

WaitForFinished() fires early

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 16.1k 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.
  • T Offline
    T Offline
    toxicate20
    wrote on 30 Jun 2011, 12:15 last edited by
    #1

    Hi guys,

    so im starting a process (which i actually have not coded myself - but still i have to use it) via a QProcess and want to see if it is finished - sure thats done like below (i think). This process is an optimization algorithm and it seems to fire the signal that it is done to my QtApp before the optimization progress even starts. You have any idea of fixing that (recall i cant change the code of the optimization app)?

    @
    QProcess *process;
    process = new QProcess( this );

    process->start("myOptimizationApp");
    process->waitForFinished();
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 30 Jun 2011, 12:55 last edited by
      #2

      On which platform do you use it?
      are you sure, the process is started?

      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
      • T Offline
        T Offline
        toxicate20
        wrote on 30 Jun 2011, 12:58 last edited by
        #3

        The system is OpenSUSE x64.

        The process is started, I'm sure because it has a GUI itself (and it opens) and waitForFinished() seems to wait for something because when it starts it will wait like 30secs into the program till it thinks about just leaving me in the rain - in contrast to this, if I leave out waitForFinished() it just continues with the routine in my QtApp right away.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 30 Jun 2011, 13:20 last edited by
          #4

          I'm not sure how it is on Linux, but on windows, this wait AFAIK only works correct for command line processes, not for UI processes....

          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
          • T Offline
            T Offline
            toxicate20
            wrote on 30 Jun 2011, 13:32 last edited by
            #5

            Okay if you say so. I'm sure there is a way to get things right with a little linux hacking. It might work if you have a bashscript checking for the process running and keep it in an while-loop. I'll post the workaround here if I've figured it out.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              beefmusta
              wrote on 1 Jul 2011, 06:48 last edited by
              #6

              Have you tried calling waitForStarted() before calling waitForFinished()?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                t3chNo
                wrote on 1 Jul 2011, 08:17 last edited by
                #7

                I recommend you to use QEventLoop. With this way, your main program won't sleep until process finishes. It'll be still usable. Sth like that:

                @
                QEventLoop waitLoop;
                connect(process, SIGNAL(finished(int, QProcess::ExitStatus),
                &waitLoop, SLOT(quit()));
                process->start();
                waitLoop.exec();
                @

                I use this sometimes.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andrew.den-exter
                  wrote on 1 Jul 2011, 10:48 last edited by
                  #8

                  waitForFinished() has a time out parameter which specifies the maximum amount of time it will wait before returning, the default value is 30000 milliseconds. If you pass a value of -1 instead it will never time out.

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    toxicate20
                    wrote on 4 Jul 2011, 06:40 last edited by
                    #9

                    Thanks guys. Andrew you plucked the right nerve as the program itself need a lot of time to start and optimize. When setting the value to -1 it will wait till the program really exits. The final solution for everyone:

                    @
                    QProcess *process;
                    process = new QProcess( this );

                    process->start("myOptimizationApp");
                    process->waitForFinished(-1);
                    @

                    1 Reply Last reply
                    1

                    7/9

                    1 Jul 2011, 08:17

                    • Login

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