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. [Solved] How to wait for process to finish

[Solved] How to wait for process to finish

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.8k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on last edited by
    #1

    Hi,
    I have the next call to run a scrip that unzip a zip:
    @
    //MainWindow.cpp
    process.startDetached("/bin/sh", QStringList()<< "/home/sg/Docs/MyScript.sh" << Arg1);
    @

    Once its unzipped, I want to make things with those files. The problem is that it seems that when I look for the files it says that they doen't exist (But they are in the folder and are readable and all ok).
    It seems that its because the process hasn't finished yet unzipping because if i put a sleep(3) it works perfect. So my question is: how can I know when has process finished? I can't use a sleep cause its a gui aplicattion working on background.

    I've tried to use the connect() but the program never goes to processFinished();

    @
    //Mainwindow.h

    private slots:
    void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
    private:
    QProcess *process;

    @

    @
    //MainWindow.cpp
    //Constructor
    { connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)),this, SLOT(processFinished(int, QProcess::ExitStatus)));
    [...]
    process.startDetached("/bin/sh", QStringList()<< "/home/sg/Docs/MyScript.sh" << Arg1);
    }

    void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    {
    qDebug() << "Hii";
    }
    @

    Thank you.

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

      Hi,

      It's because you are calling startDetached (which by the way is a static function).

      Just call start and you should see your slot getting called when the process is done.

      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
      0
      • R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        Wow! Finally a problem with an easy answer! :D haha i had start and changed it into stardetached dunno why... I think I should check the difference between them :D

        Thank you!

        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