我想从 QProcess 中获取标准输出到 QTextEdit 中。 如果我这样做,它会起作用:
QObject::connect(process, SIGNAL(readyReadStandardOutput()),
this, SLOT(readStdOutput()));
和
void myClass::readStdOutput()
{
teOutput->insertPlainText(process->readAllStandardOutput());
}
虽然子程序不断打印到标准输出(在终端中测试) QTextEdit 每隔几秒更新一次输出 block 。
最佳答案
来自QIODevice
手册:
Certain subclasses of QIODevice, such as QTcpSocket and QProcess, are asynchronous. This means that I/O functions such as write() or read() always return immediately, while communication with the device itself may happen when control goes back to the event loop. QIODevice provides functions that allow you to force these operations to be performed immediately, while blocking the calling thread and without entering the event loop.
要尝试的另一件事是禁用任何缓冲区,手册没有针对 QProcess 提及它,但您可以尝试一下:
Some subclasses, such as QFile and QTcpSocket, are implemented using a memory buffer for intermediate storing of data. This reduces the number of required device accessing calls, which are often very slow.
...
QIODevice allows you to bypass any buffering by passing the Unbuffered flag to open().
https://stackoverflow.com/questions/10223777/
相关文章:
ruby-on-rails - Rails 中的 ActiveRecord::MissingAttr
c# - 在 BackgroundWorker 线程上创建 FlowDocument
ruby-on-rails - Rails Association Validations : Th
typo3 - 将 locallang 值插入 TypoScript [stdWrap]
python - beautiful soup 从谷歌搜索中提取一个 href
imagemagick - 使用 imagemagick 从图像中裁剪矩形区域