PDA

View Full Version : QProcess problem (Main program hangs)



sincnarf
8th October 2007, 11:36
Hello. I am trying to call the eog command (it's an image viewing software) from my Qt application. This is the code.

void MainWindow::doRawViewer(){
QMessageBox::information(
this,
tr("Required Save"),
tr("Save the image first in order to view this image under the system's default image viewer"));
QString fileName = doRawSave();
if (fileName.isNull())
return;
QProcess viewImageProcess(0);

#if defined(Q_OS_WIN32)
viewImageProcess.start(fileName);
#elif defined(Q_OS_LINUX)
viewImageProcess.execute(QString("eog ") + fileName);
// viewImageProcess.start(QString("eog ") + fileName);
#endif
}

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.

jacek
8th October 2007, 14:20
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?


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

jpn
8th October 2007, 14:28
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.

jacek
8th October 2007, 14:48
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:

QProcess p;
...
QProcess::execute( ... );
...
p.waitForFinished( ... );

sincnarf
11th October 2007, 10:15
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?

wysota
11th October 2007, 10:26
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.