Results 1 to 6 of 6

Thread: QProcess problem (Main program hangs)

  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess problem (Main program hangs)

    Hello. I am trying to call the eog command (it's an image viewing software) from my Qt application. This is the code.
    Qt Code:
    1. void MainWindow::doRawViewer(){
    2. QMessageBox::information(
    3. this,
    4. tr("Required Save"),
    5. tr("Save the image first in order to view this image under the system's default image viewer"));
    6. QString fileName = doRawSave();
    7. if (fileName.isNull())
    8. return;
    9. QProcess viewImageProcess(0);
    10.  
    11. #if defined(Q_OS_WIN32)
    12. viewImageProcess.start(fileName);
    13. #elif defined(Q_OS_LINUX)
    14. viewImageProcess.execute(QString("eog ") + fileName);
    15. // viewImageProcess.start(QString("eog ") + fileName);
    16. #endif
    17. }
    To copy to clipboard, switch view to plain text mode 

    eog runs properly and it correctly displays the image, the problem is when I close eog, my Qt application hangs. Is this a memory problem or I'm just not using QProcess::execute() and QProcess::start() correctly?

    Also, I do not know how to use task manager in ubuntu. can anyone point me to how I can manage the Qt Application when it hangs? It does not force quit at all.
    Image Analysis Development Framework Using Qt (IADFUQ)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess problem (Main program hangs)

    Quote Originally Posted by sincnarf View Post
    Is this a memory problem or I'm just not using QProcess::execute() and QProcess::start() correctly?
    QProcess::execute() is a static method, so you don't need a QProcess instance to invoke it, and even if you do have one, it won't affect it.

    Do you wait for that eog application to close somewhere in your program?

    Quote Originally Posted by sincnarf View Post
    Also, I do not know how to use task manager in ubuntu. can anyone point me to how I can manage the Qt Application when it hangs?
    man ps
    man kill

  3. The following user says thank you to jacek for this useful post:

    sincnarf (11th October 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess problem (Main program hangs)

    QProcess::execute():
    Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    sincnarf (11th October 2007)

  6. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess problem (Main program hangs)

    Quote Originally Posted by jpn View Post
    Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process.
    Yes, but this doesn't explain the hanging. I wonder whether the application, doesn't look like this:
    Qt Code:
    1. ...
    2. QProcess::execute( ... );
    3. ...
    4. p.waitForFinished( ... );
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to jacek for this useful post:

    sincnarf (11th October 2007)

  8. #5
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess problem (Main program hangs)

    I didn't use waitForFinished because this means I have to close eog first before I can get back to my mainwindow. What I was trying to do was to both simultaneously run my mainwindow and the process eog.

    Does this mean I can't run my mainwindow along with the QProcess that calls eog?
    Image Analysis Development Framework Using Qt (IADFUQ)

  9. #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: QProcess problem (Main program hangs)

    You can, you just can't use the static method approach. You need to create a regular QProcess object (on heap), call start() on it and voila. You should be able to continue using your application while the viewer executes. If your application still hangs, it means the process has nothing to do with it - try commenting out those lines related to QProcess and see if the application hangs or not.

  10. The following user says thank you to wysota for this useful post:

    sincnarf (13th October 2007)

Similar Threads

  1. Problem with qprocess
    By resal in forum Qt Programming
    Replies: 8
    Last Post: 29th August 2007, 22:13
  2. New to QT, problem displaying main window...
    By McCall in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2007, 14:27
  3. QProcess hangs
    By Skizmo in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2007, 10:27
  4. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  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.