Results 1 to 3 of 3

Thread: Question about QProcess

  1. #1
    Join Date
    Jul 2006
    Qt products

    Default Question about QProcess

    I tried to use QProcess to run program B from program A. I want to know when program B finished so the program A could do something else.

    In CentOS system, both program A and B are GUI programs:

    in mainwindow.h:

    QProcess proc;
    private slots:
    void procFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void on_execBPushButton_clicked();

    in mainwindow.cpp

    void MainWindow:n_execBPushButton_clicked()
    QStringList args;
    args << "1";
    connect(&proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished(int, QProcess::ExitStatus)));
    proc.start("<path>/B", args);

    void MainWindow:rocFinished(int exitCode, QProcess::ExitStatus exitStatus)
    cout << "procFinished() is called" << endl;

    These are the code to handle the QProcess. I found if I use proc.waitForFinish(), the program A could not refresh the GUI. I know that because after B is launched, I drag the B across A and leave the "trace" on A forever. If I delete this waitForFinsihed(), program A and B both are refreshing when they need.

    Also, the "procFinished() is called" did not display after program B is terminated. Instead, the "... is called" display when program A is terminated. So, could anyone tell me what I did wrong?

    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    Default Re: Question about QProcess

    Don't call the function waitForFinished() and your main program won't stop and wait for the other program to finish.

  3. #3
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 717 Times in 707 Posts
    Qt products
    Windows Android

    Default Re: Question about QProcess

    You are already connecting to the QProcess:finished() signal, so you will get notified when the process exits. As ChrisW67 says, no need to call QProcess::waitForFinished(). If there are things that Program A should not do while Program B is executing (like allow the "execBPushButton" to be clicked again), then you should disable it in the on_execBPushButton_clicked() slot and enable it again in the procFinished() slot.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qprocess question
    By connect_qt in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2011, 16:32
  2. A question about QProcess
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2011, 17:27
  3. QProcess question
    By PH5 in forum Newbie
    Replies: 0
    Last Post: 4th February 2010, 23:43
  4. Question about QProcess
    By lni in forum Qt Programming
    Replies: 5
    Last Post: 27th April 2007, 23:08
  5. QProcess Question
    By Vash5556 in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2007, 16:24


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.