void
QProcess::
start
(const
QString
&
program
, const
QStringList
&
arguments
,
OpenMode
mode
= ReadWrite)
不能传入引用参数
官方文档解释:
void
QProcess::
start
(const
QString
&
program
, const
QStringList
&
arguments
,
OpenMode
mode
= ReadWrite)
Starts the given
program
in a new process, passing the command line arguments in
arguments
.
The
QProcess
object will immediately enter the Starting state. If the process starts successfully,
QProcess
will emit
started
(); otherwise,
errorOccurred
() will be emitted.
Note: Processes are started asynchronously, which means the
started
() and
errorOccurred
() signals may be delayed. Call
waitForStarted
() to make sure the process has started (or has failed to start) and those signals have been emitted.
Note: No further splitting of the arguments is performed.
Windows: The arguments are quoted and joined into a command line that is compatible with the
CommandLineToArgvW()
Windows function. For programs that have different command line quoting requirements, you need to use
setNativeArguments
(). One notable program that does not follow the
CommandLineToArgvW()
rules is cmd.exe and, by consequence, all batch scripts.
If the
QProcess
object is already running a process, a warning may be printed at the console, and the existing process will continue running unaffected.
代码示例:
QProcess pExe(0);
QString str7z;
//命令exe
str7z.append("E:\\maozg tools\\OuterNetPacketMaker\\Bin\\7z.exe");
//命令参数
QStringList strCMD;
strCMD.append("x");
strCMD.append("D:\\111.zip");
//引用参数
QString strArg;
strArg.append("-y");
strArg.append("-o");
strArg.append("D:\\");
strArg.append("*.txt");
strArg.append("-r");
pExe.setNativeArguments(strArg);
pExe.start(str7z, strCMD);
pExe.waitForStarted();
pExe.waitForFinished();
QString strTemp = QString::fromLocal8Bit(pExe.readAllStandardOutput());
QMessageBox testMassage1;
testMassage1.setText(strTemp);
testMassage1.exec();