Class Qdesktopservices provides methods to access popular desktop services such as browsers, players, e-mail clients, and we use Qdesktopservices:: OpenUrl (URL) to open Web browsing based on a specified URL Returns true if it succeeds, or false if the result is returned. The corresponding can open the file (clip), executable program and so on!
If you want to start other applications that use Qprocess, when an error occurs, you can describe the type of error that occurred based on the specified error.
Description: After the interface starts, you can launch an externally specified program by clicking the button!
Mywidget::mywidget (Qwidget *parent):
Qwidget (parent)
{
Qpushbutton *push_button = new Qpushbutton (this);
Connect (Push_button, SIGNAL (clicked ()), this, SLOT (StartProcess ()));
Process = new qprocess ();
Qobject::connect (Process, SIGNAL (Error (qprocess::P rocesserror), this, SLOT (Processerror (qprocess::P rocesserror)) );
}
void Mywidget::startprocess ()
{
Process->start ("E:\\a\\b.exe");
}
void Mywidget::p rocesserror (qprocess::P rocesserror error)
{
Switch (Error)
{
Case Qprocess::failedtostart:
Qmessagebox::information (0, "Failedtostart", "Failedtostart");
Break
Case qprocess::crashed:
Qmessagebox::information (0, "Crashed", "Crashed");
Break
Case Qprocess::timedout:
Qmessagebox::information (0, "Failedtostart", "Failedtostart");
Break
Case QPROCESS::WRITEERROR:
Qmessagebox::information (0, "timedout", "timedout");
Break
Case QPROCESS::READERROR:
Qmessagebox::information (0, "Readerror", "Readerror");
Break
Case QPROCESS::UNKNOWNERROR:
Qmessagebox::information (0, "Unknownerror", "Unknownerror");
Break
Default
Qmessagebox::information (0, "Default", "Default");
Break
}
}
As above: When the program exits, the external program that is started does not exit with the main program exit, if this is not expected to happen.
You can add the following code before the program exits
if (process)
{
Process->close ();
Delete process;
Process = NULL;
}
Http://blog.sina.com.cn/s/blog_a6fb6cc90101drvj.html
How to start other applications in Qt (if unsuccessful, there are a number of reasons why Qprocess::P rocesserror available for analysis)