Qt Literacy-QProcess Theory Summary

Qt literacy-QProcess theory summary_qprocess ends the process_Sunstorm's blog-CSDN blog

QProcess allows us to treat processes as sequential I/O devices. Because QProcess itself inherits from the QIODevice class, we can read and write to the process just like using QTcpSocket to access a network connection. You can then call write() to write to the process's standard input, and read(), readLine(), and getChar() to read the standard output. Because it inherits QIODevice, QProcess can also be used as an input source for QXmlReader, or used to generate data to be uploaded using QNetworkAccessManager.

When the external process exits, QProcess re-enters the NotRunning state (initial state) and emits the finished() signal.
The finished() signal provides the exit code and exit status of the process as parameters. You can also call exitCode() to get the exit code of the last completed process, and call exitStatus() to get its exit status.

If an error occurs at any point in time, QProcess will emit the erroroccurs() signal. You can also call error() to find the type of error that occurred last time, and call state() to find the status of the current process.
——————————————
Copyright statement: This article is an original article by CSDN blogger “Solar Storm” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this copy when reprinting statement.
Original link: https://blog.csdn.net/qq_43680827/article/details/129440680

The finished signal and common signals after calling the external exe in QProcess_qprocess ends_Littlehero_121's blog-CSDN blog

1. You can refer to the relevant link: https://doc.qt.io/Qt-5/qprocess.html#finished

2. Pay attention to starting the following 4 signals when using them. Use start(), otherwise there will be problems with startup.

Pay attention to the difference between start() and startDetached() here: https://blog.csdn.net/kucoffee12/article/details/75200101

The following 4 signals related to start: (the following are bindings)

QProcess *process = new QProcess;
    connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(redFromStdOut()));
    connect(process, SIGNAL(readyReadStandardError()), this, SLOT(redFromStdErr()));
    connect (process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished (int,QProcess::ExitStatus)));
 
The program ends normally or abnormally. The structure is as follows:

 enum ExitStatus {         NormalExit,         CrashExit     }; void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {     if(exitStatus == QProcess::NormalExit)     {         //The program ends normally     }     else     {         //The program ends abnormally     } } After entering the normal end, you can judge that the called exe program has been completed. In this way, you can know when the called execution program terminates;














 

Guess you like

Origin blog.csdn.net/thanklife/article/details/131030612