Results 1 to 5 of 5

Thread: How to wait for process to finish

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to wait for process to finish

    Hi,
    I have the next call to run a scrip that unzip a zip:
    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.


    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to wait for process to finish

    Don't use startDetached() but a real QProcess instance and connect to its signals.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wait for process to finish

    QProcess process;
    And then how do you run the script? process.???

    To connect it I suppose you mean to do something like:

    connect(this, SIGNAL(process.finished()), this, SLOT(HasFinished());

    declaring in the .h

    Qt Code:
    1. private slots: HasFinished();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to wait for process to finish

    Quote Originally Posted by roseicollis View Post
    QProcess process;
    And then how do you run the script? process.???
    I recommend looking at the Qt documentation for QProcess.

    Quote Originally Posted by roseicollis View Post
    To connect it I suppose you mean to do something like:

    connect(this, SIGNAL(process.finished()), this, SLOT(HasFinished());
    Yes, but with a sender that actually makes sense and a valid signal name.

    Quote Originally Posted by roseicollis View Post
    declaring in the .h

    Qt Code:
    1. private slots: HasFinished();
    To copy to clipboard, switch view to plain text mode 
    [/quote]
    Right, but with actually correct syntax.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wait for process to finish

    Ok thank you

    Edited: Implemented with process.start() and working
    Last edited by roseicollis; 22nd December 2014 at 18:01.

Similar Threads

  1. Replies: 1
    Last Post: 2nd September 2013, 23:49
  2. createRequest does not finish
    By brcontainer in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2013, 22:07
  3. Wait Condition Indication to User Using Loading/Wait Message
    By vivek.panchal in forum Qt Programming
    Replies: 4
    Last Post: 14th August 2012, 17:40
  4. Replies: 5
    Last Post: 15th December 2011, 01:06
  5. Wait for a function to finish
    By fitzy in forum General Programming
    Replies: 3
    Last Post: 26th October 2009, 19:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.