我以为我将使用以下代码从 QProcess 获取输出:
// Start the process
process.start(tr("php-cgi www/test.php"),QIODevice::ReadWrite);
// Wait for it to start
if(!process.waitForStarted())
return 0;
// Continue reading the data until EOF reached
QByteArray data;
while(process.waitForReadyRead())
data.append(process.readAll());
// Output the data
qDebug(data.data());
qDebug("Done!");
我期望看到程序的输出打印到调试控制台,但我看到的是:
Done!
我知道:
我在这里做错了什么?
最佳答案
在开始流程调用之前:
process.setProcessChannelMode(QProcess::MergedChannels);
它会导致将所有内容(甚至 STDERR 输出)打印到 STDOUT 输出。
关于qt - 如何从 QProcess 获取 STDOUT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852587/