1. How to call an external exe program
non-blocking mode
QProcess *myProcess = new QProcess(this);
QString program = "D:\\WinPie.exe";
QStringList arguments;//parameters passed to exe
QString piex = QString::number(this->x());//int type to QString
QString piey = QString::number(this->y());//
arguments.append(piex);//Transfer the screen coordinate x of the window
arguments.append(piey);// transfer the screen coordinate y of the window
myProcess->start(program,arguments);//Start the exe program and pass parameters at the same time.
The practice of external program exe is:
In the case where there is no need to obtain the parameters passed by the call, no additional operations are required.
If you need to parse the passed parameters.
#include <stdlib.h>
int main(int argc, char *argv[])
{
In the main function, argc is the number of parameters, generally 1
argv[] is a string array, argv[0] puts the path of the program, and the general parameters start from subscript 1.
int pieX = 200;
int pieY = 800;
if(argv[1] !=nullptr && argv[2] != nullptr)
{
pieX = atol(argv[1]);//Extract the parameters passed in.
pieY = atol(argv[2]); //Convert char* to int.
}
}
2. Determine the status of the program started by QProcess->start
Use the myProcess->state() function, which has QProcess::NotRunning,
QProcess::Running and QProcess::Starting three states.