Reputation: 356
I wrote two Qt applications. One is the main and the other is a side way.
I am running Linux.
I read about QProcess
so I wrote this code:
QApplication a(argc, argv);
MainWindow w;
w.show();
QProcess P(&w);
QString programPath;
programPath=
"/Documents/Qt/test1-build-desktop-Qt_4_8_1_in_PATH__System__Release/test1";
P.start(programPath);
return a.exec();
However, nothing happens and just my main app (w
) runs.
What is my fault? Please help me.
Upvotes: 1
Views: 9671
Reputation: 356
My fault was in the path to executable.
I edit it, very simple and got it work.
QApplication a(argc, argv);
MainWindow w;
w.show();
QProcess P(&w);
QString programPath;
programPath=
"/home/erfan/Documents/Qt/test1-build-desktop- Qt_4_8_1_in_PATH__System__Release/test1";
P.start(programPath);
return a.exec();
And it work properly.
Another way is to put the executable directly in root:
(/ somthings)
Upvotes: 1
Reputation: 22920
the issue is that P.start(programPath);
is a non blocking operation. Furthermore, the application output is redirected , and can be accessible from the Qprocess object only.
Edit:
It seems that the path to the executable is incorrect. Anything which starts with "/" will be considered an absolute path.
You probably need to write a QObject
subclass to monitor the process you started. This object will catch process signals as kassak pointed out.
class ProcessMonitor : public QObject {
Q_OBJECT
public slots:
void notifyStart();
void handleError( QProcess::ProcessError error );
void notifyStop(int exitCode, QProcess::ExitStatus ex);
}
In each slot you can just print a message. Then you can do the connections
ProcessMonitor montinor;
QObject::connect(&P,SIGNAL(error(QProcess::ProcessError)),
&monitor,SLOT(handleError( QProcess::ProcessError error )) );
Upvotes: 3
Reputation: 92
You can use
#include <cstdlib>
std::system("/path/to/executable &");
Upvotes: -1