前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >关于void QProcess::start参数问题的解决

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

作者头像
Sky_Mao
发布2020-07-24 10:05:39
1.6K0
发布2020-07-24 10:05:39
举报
文章被收录于专栏:生命不息,Codeing不止

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

问题: const QStringList &arguments 只能传入命令本身的参数,不能传入引用参数。

解决: 在windows下面需要使用setNativeArguments() 添加引用参数

Qt官方文档描述: 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.

使用代码实例:

代码语言:javascript
复制
void Unpack()
{
    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();
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档