关于void QProcess::start参数问题的解决

void  QProcess:: start (const  QString  & program , const  QStringList  & arguments OpenMode   mode  = ReadWrite)

const  QStringList  & arguments 只能传入命令本身的参数
不能传入引用参数
在windows下面需要使用 setNativeArguments () 添加引用参数

官方文档解释:
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.
The  OpenMode  is set to  mode .
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();





  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值