readAll() 或 readAllStandardOutput() 在执行之前也返回一个空字符串
readAll() or readAllStandardOutput() is returning an empty string that too before execution
正如标题中所定义的那样,这两个函数都返回一个空字符串。 让我描述一下我的场景,我正在执行一个 python 文件,它最后正在打印文本,文本在执行后发布在应用程序输出上,但给定的输出不会被复制。 此外,我的 Python 脚本需要 30 到 40 秒才能执行,但 readAll 函数在加载脚本后立即执行。
我的函数正在执行 Python 脚本:
QString text = ui->textEdit->toPlainText();
QString path = "D:/DS Project/Treegramming";
QString command("py");
QStringList params = QStringList() << "nlp.py";
params << text;
QProcess *process = new QProcess();
process->startDetached(command, params, path);
process->waitForFinished(30000);
QByteArray ba = "";
process->waitForReadyRead(30000);
ba += process->readAllStandardOutput();
qDebug() << ba ;
再次重复,qDebug(( 在整个脚本执行之前给出空输出。
考虑这条线...
process->startDetached(command, params, path);
在这里,您实际上是在调用静态startDetached
成员,该成员与您新创建的QProcess
无关。 因此,您不会看到任何标准输出/错误。
相反,您应该将非静态start
成员与类似(未经测试(的内容一起使用...
process->setWorkingDirectory(path);
process->start(command, params);
相关文章:
- 返回常量对象引用 (getter) 和仅返回字符串有什么区别?
- C 字符串返回字符串的整数/双精度/长整型值
- 如何从COM模块中的函数返回字符串数组?
- React Native (Android):无法通过 JNI 在 jobject 中返回字符串
- 我如何在函数 cpp 中返回字符串
- 我有一个返回字符串向量的函数.它需要两个字符串,并且返回一个字符串中缺少的字符串
- 格式化返回字符串C++
- 返回字符串vs通过引用传递字符串以更新值
- 如何在不使用 STL 的情况下从函数反转字符串后返回字符串C++?
- 使用 ctypes 从函数返回字符串C++会给出大的 int,而不是 char 指针
- 从 C++ 中的模板函数返回字符串和整数
- 返回字符串的散点回文计数
- C++重载字符串 [] 运算符以返回字符串和
- 返回字符串和不同向量数据类型的映射C++
- 字符串函数不返回字符串? C++
- 从函数返回字符串C++错误
- 如何在返回字符串的函数中不忽略void值
- 我想将字符串转换为 Json 格式并返回字符串向量作为答案
- C - 返回字符串时的分割故障
- 使用向量和字符串函数返回字符串