qt得到python输出结果_Qt5.6 QProcess::start获取标准输出

平台:windows10

我使用QProcess的start函数执行本地(当前目录下)的python文件后,无法从readAllStandardOutput获取标准输出。

python文件的代码:

print “hello,world”

Qt代码:

#include

#include

#include

#include

void fun1(){

QProcess process;

process.start("python test.py");

process.waitForFinished();

QByteArray a = process.readAllStandardOutput();

qDebug()<

}

int main(){

fun();

}

输出的a只有"",没有数据,但是在cmd中运行python文件,没错,且可以输出"hello,world"。

在我使用process.execute这个函数直接执行python文件时,python文件可以正常执行,且可以输出"hello,world"到Qt的终端。

#include

#include

#include

#include

#include

void fun2(){

QStringList args("F:/test.py");

QProcess process;

process.execute(QString("Python.exe"), args);

QByteArray a = process.readAllStandardOutput();

process.waitForFinished();

qDebug()<

你可能感兴趣的:(qt得到python输出结果)