Results 1 to 8 of 8

Thread: exitCode problem in QProcess

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default exitCode problem in QProcess

    Hello, i hava a problem with QProcess.
    I made this connection:
    Qt Code:
    1. connect ( myProcess , SIGNAL ( finished ( int , QProcess::ExitStatus ) ) , this , SLOT ( processVNCFinished ( int , QProcess::ExitStatus ) ) );
    To copy to clipboard, switch view to plain text mode 

    so when the process finish i call the slot processVNCFinished.
    This is my processVNCFinished slot:
    Qt Code:
    1. void mainWindow::processVNCFinished ( int exitCode , QProcess::ExitStatus exitStatus )
    2. {
    3. if ( exitStatus == QProcess::CrashExit )
    4. {
    5. qDebug () << "VNC client program crashed\n";
    6. }
    7. else if ( exitCode != 0 )
    8. {
    9. qDebug () << "VNC client program failed\n";
    10. }
    11. else
    12. {
    13. qDebug () << "VNC client program OK!\n";
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    i'm going to call vncviewer and when i close the vncviewer window clicking on the "X" on the right top window i get an exitCode = 1. Shouldn't i receive a 0 like exitCode?
    In this way i always fall into qDebug () << "VNC client program failed\n" and instead i'd like to go into qDebug () << "VNC client program OK!\n".
    Thx

  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: exitCode problem in QProcess

    This seems to be an issue with vncviewer and not Qt. Can you verify that vncviewer returns 0 when run from console?

  3. #3
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: exitCode problem in QProcess

    what should i do to verify it?
    thx

  4. #4
    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: exitCode problem in QProcess

    Call it from bash and use && and || to check if the result is 0 or not, for example:

    $ vncviewer && echo "zero"

    If you receive the text "zero", it means vncviewer returned 0.

    $ vncviewer || echo "not zero"

    This will check if it returns something else than 0.

  5. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: exitCode problem in QProcess

    echo works in this case:

    $ vncviewer || echo "not zero"

    so vnc doesn't return zero.
    well, my code is ok, i have to catch when exitCode is 1? this means the vnc is close correctly?

  6. #6
    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: exitCode problem in QProcess

    I don't know if it is 1. It is "not 0". Can't you just rely on QProcess::ExitStatus?

  7. #7
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: exitCode problem in QProcess

    mmm..i modified my code in this way:
    Qt Code:
    1. void mainWindow::processVNCFinished ( int exitCode , QProcess::ExitStatus exitStatus )
    2. {
    3. if ( exitStatus == QProcess::CrashExit )
    4. {
    5. qDebug () << "VNC client program crashed\n";
    6. }
    7. else if ( exitCode != 0 && exitStatus != QProcess::NormalExit )
    8. {
    9. qDebug () << "VNC client program failed\n";
    10. }
    11. else
    12. {
    13. qDebug () << "VNC client program OK!\n";
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    now it works.

  8. #8
    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: exitCode problem in QProcess

    Qt Code:
    1. if(exitCode != 0 && exitStatus != QProcess::NormalExit)
    To copy to clipboard, switch view to plain text mode 
    You will never enter this branch, because you already checked that exitStatus is QProcess::NormalExit, so the second part of this if will always be false.

Similar Threads

  1. QProcess problem (Main program hangs)
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2007, 09:26
  2. Problem with qprocess
    By resal in forum Qt Programming
    Replies: 8
    Last Post: 29th August 2007, 22:13
  3. QThread and QProcess problem
    By codebehind in forum Qt Programming
    Replies: 13
    Last Post: 7th August 2007, 08:11
  4. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 11:24
  5. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30

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.