gpt4 book ai didi

c++ - 如何使用 QProcess 中的 bash 命令 'which'

转载 作者:行者123 更新时间:2023-11-30 04:23:27 24 4
gpt4 key购买 nike

我是一名使用 Qt 的学生程序员,我似乎遇到了使用 QProcess 启动 bash 命令“which”以尝试收集应用程序安装图的问题。我有以下代码,我真的不知道我可能遗漏了什么。我引用了 QProcess documentation仍然无法弄清楚出了什么问题。

每次运行此代码时,都不会在指定目录中创建文件。如果没有构建文件,应用程序将无法继续。

//datatypes
QProcess *findFiles = new QProcess();
QStringList arguments;
QStringList InstallationList;
QString program = "/bin/bash";
QString currentUsersHomeDirectory = QDir::homePath();
QString tmpScriptLocation = currentUsersHomeDirectory;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
//generate file with list of files found
tmpScriptLocation += ".whichBAScriptOutput";
arguments << QString(QString("which -a certainFile >> ") += tmpScriptLocation);
findFiles->setProcessEnvironment(env);
findFiles->start(program,arguments);
findFiles->waitForFinished();

最佳答案

位于 /usr/bin/ 所以尝试更改路径..

编辑:您需要将 QProcess 的信号 readyReadStandardOutput() 连接到您的插槽。实际上,如果您查看文档,QProcess 继承自 QIODevice。这意味着您可以执行以下操作:

while(canReadLine()){
string line = readLine();
...
}

如果您已经在 Qt 中编写过客户端-服务器应用程序,我相信您已经了解了伪代码..

关于c++ - 如何使用 QProcess 中的 bash 命令 'which',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13371601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com