How to start other applications in Qt (if unsuccessful, there are a number of reasons why Qprocess::P rocesserror available for analysis)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.