Results 1 to 14 of 14

Thread: QProcess object not emitting finished(int) signal

  1. #1
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QProcess object not emitting finished(int) signal

    Hello,

    I have a weird trouble. I have created a QProcess object and started an external program. But... when program finishes, object is not emitting finished signal. How is this possible? What can I do to workaround this?

    My code example:
    Qt Code:
    1. launcher::launcher(QWidget *parent, Qt::WFlags flags)
    2. : QDialog(parent, flags)
    3. {
    4. QProcess program;
    5. Sleep(3000);
    6. program.start("/path/to/my/program.exe");
    7. connect(&program, SIGNAL(finished(int)), this, SLOT(OnExit()));
    8. }
    9.  
    10.  
    11. void launcher::OnExit()
    12. {
    13. QMessageBox::information(this,"","Izhod");
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 14th November 2008 at 22:39. 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 object not emitting finished(int) signal

    Your program doesn't even start. The QProcess object that controls it gets destroyed when you leave the constructor. Create it on heap instead.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess object not emitting finished(int) signal

    this slot works, but your programm terminated immediately. create QProcess in a heap.
    wysota, you was first
    Last edited by spirit; 14th November 2008 at 08:08. Reason: updated contents
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    Well, actually my program does not end. I did not paste the whole constructor code .
    After connect.... line I have this:

    while (true)
    {
    Sleep(1000)
    }

    So I stay in constructor and my program keeps running. It stays in constructor because I don't want it to open GUI. It's ugly I know but it works and runs hidden. With Sleep I prevent 100% CPU utilization.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess object not emitting finished(int) signal

    create console app and run process.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    I don't want to open any window, not even console. I want it to run as services do (completely hidden), but don't know how to program real service.

    Now it seems like signal-slots communication does not work until execution leaves constructor??

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess object not emitting finished(int) signal

    if you need a service you can use QtService from Qt Solutions.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. The following user says thank you to spirit for this useful post:

    Tiansen (14th November 2008)

  9. #8
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    I never programmed a service and I want to be sure that I cannot achieve my goal any other way before diving into this.

    I still do not understand why it does not work as it is now.

  10. #9
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    If I comment out while loop so that it opens GUI then object indeed emits signal. So it seems that with that loop I blocked processing of signals. Any other idea to create a "hidden" launcher without programming a service?

  11. #10
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    Hmmm, now I figured out something. I can leave constructor as in first post (without while loop), but just comment out following line in main.cpp:

    //w.show();

    and it works as intended (launches program, shows dialog box when program exits and stays completely hidden). Does this have any side effect?

  12. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess object not emitting finished(int) signal

    what do you want to achive? do you use any GUI in your app or you need only start another process, so you don't need GUI?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #12
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    Okay, I wil try to explain:

    1. I DON'T want ANY window (NO GUI, no console either)

    2. I just want to first run 2 other processes and then restart them if one of them dies/exits.

    This is all I want. And it seems I can achieve that if i comment out w.show().


    P.S.: I only had that QMessageBox because I tested behaviour. Application must stay completely silent normally.

  14. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess object not emitting finished(int) signal

    there is some "magic" to hidding your app (i.e. that it don't appear in task bar), but for this "magic" you need to use platform dependent code.
    so, I suggest to use QtService or take a look at QSystemTrayIcon
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  15. The following user says thank you to spirit for this useful post:

    Tiansen (14th November 2008)

  16. #14
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess object not emitting finished(int) signal

    I think I "invented" such magic too

Similar Threads

  1. Replies: 3
    Last Post: 15th April 2007, 19:16
  2. Replies: 2
    Last Post: 17th May 2006, 21:01
  3. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.