Results 1 to 5 of 5

Thread: QProcess calls finished signal before started process exits

  1. #1
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess calls finished signal before started process exits

    I'm new to QT so I'm sure I'm either misunderstanding something or just doing something wrong.
    The problem is that when I run the code below, it opens up the application and also immediately
    calls the finished() function even though the application is still running. I wouldn't expect it to
    emit the finished signal until after the application has exited?

    What am I missing?

    Here is my test code.

    *****************************************
    mainwindow.h
    ==========
    Qt Code:
    1. private slots:
    2. void procEditFinished(int exitCode, QProcess::ExitStatus exitStatus);
    3.  
    4. private:
    5. QProcess *procEdit;
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    ============
    Qt Code:
    1. void MainWindow::on_btnEdit_clicked()
    2. {
    3. QString app = "/usr/bin/gedit";
    4.  
    5. arg << "file.txt";
    6. procEdit = new QProcess(this);
    7. connect(procEdit, SIGNAL(finished(int, QProcess::ExitStatus)),
    8. this, SLOT(procEditFinished(int, QProcess::ExitStatus)));
    9.  
    10. procEdit->start(app, arg);
    11. }
    12.  
    13. void MainWindow::procEditFinished(int exitCode, QProcess::ExitStatus exitStatus)
    14. {
    15. qDebug("exitCode= %d, exitStatus= %d", exitCode, exitStatus);
    16. procEdit->deleteLater();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 2nd June 2012 at 01:45. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess calls finished signal before started process exits

    My guess would be that gedit forks and quits the parent process to detach itself from the terminal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess calls finished signal before started process exits

    Thanks for the reply. I don't think that is the problem. I see the same behavior when executing a linux shell script. I've also done the same thing with gedit using mono (linux implementation of .net) which implements a similar Process class. That class doesn't show gedit exiting until I close it.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess calls finished signal before started process exits

    Gedit V2+ only allows a single running instance. If there is an existing gedit instance running then the new instance you start communicates the file name to the existing instance and terminates immediatly. If there is no existing instance of gedit running then the process does not terminate until you close that instance of the editor i.e. what you were expecting. As far as I can tell there is no way to suppress this behaviour.

  5. #5
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess calls finished signal before started process exits

    You're right. It works if no other instance is running to receive the new file being opened so the other instance can terminate. At least understanding what's happening helps with how to handle it. Thanks.

Similar Threads

  1. QProcess finishes but never emits finished signal
    By BettaUseYoNikes in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2011, 08:01
  2. Qt Creator: The process could not be started!
    By AlphaWolf in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 03:31
  3. Replies: 8
    Last Post: 27th August 2009, 14:51
  4. QProcess object not emitting finished(int) signal
    By Tiansen in forum Qt Programming
    Replies: 13
    Last Post: 14th November 2008, 12:17
  5. Replies: 2
    Last Post: 30th March 2007, 08:10

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.