当前位置: 代码迷 >> QT开发 >> qt4中怎样获取cout或者printf的输出,然后显示在text上,该如何解决
  详细解决方案

qt4中怎样获取cout或者printf的输出,然后显示在text上,该如何解决

热度:275   发布时间:2016-04-25 05:10:47.0
qt4中怎样获取cout或者printf的输出,然后显示在text上
cout或者printf的输出时直接输出到控制台console上,然后我想在控制台上获取这些输出,并且显示在一个text上,请问各位大侠有什么好方法没有,请说详细点,我才刚学qt不久,谢谢!!

------解决方案--------------------
在Winodws下你可以利用ReadConsole来获取控制台的输出~~`
------解决方案--------------------
QTextStream::QTextStream ( FILE * fileHandle, QIODevice::OpenMode openMode = QIODevice::ReadWrite )
Constructs a QTextStream that operates on fileHandle, using openMode to define the open mode. Internally, a QFile is created to handle the FILE pointer.

This constructor is useful for working directly with the common FILE based input and output streams: stdin, stdout and stderr.
Example:

 int i = 5;
 QTextStream out(stdout);
 cout << i;

然后 用 QPlainTextEdit 显示 out
------解决方案--------------------
试试重定向stdout至文件:
freopen ("myfile.txt","w",stdout);
//调用dll
...
printf ("printf is redirected to a file.\n");
fclose (stdout);
  相关解决方案