Dear all,
I search in the web and I found out that a way to redirect std::cout to a QTextEditor is to implement a class
class QDebugStream : public std::basic_streambuf<char>
class QDebugStream : public std::basic_streambuf<char>
To copy to clipboard, switch view to plain text mode
The implementation of the class is in the attached file.
I made the call of the class in this way (Ui_outputView I designed myself through qtDesigner, it is just a Widget containing a QTextEditor "consoleTextEdit")
class OutputView
: public QWidget,
private Ui_outputView
{
Q_OBJECT
public:
OutputView
(QWidget* parent
= NULL){ setupUi(this);
consoleTextEdit->toPlainText();
qout = new QDebugStream(std::cout, consoleTextEdit);
}
~OutputView(){}
private:
QDebugStream *qout;
};
class OutputView : public QWidget, private Ui_outputView
{
Q_OBJECT
public:
OutputView(QWidget* parent = NULL){
setupUi(this);
consoleTextEdit->toPlainText();
qout = new QDebugStream(std::cout, consoleTextEdit);
}
~OutputView(){}
private:
QDebugStream *qout;
};
To copy to clipboard, switch view to plain text mode
The code works fine, I can display the output text but I have two main questions:
1- I would like that the text is displayed not all at once: so far the text is displayed when the function that contains all the prints "cout<<" returns. I would like to see the output as in happen in the console when the cout is called.
2- is it worth perhaps to use QTextStream to catch the standard output and display it in a QTextEdit? Any hints on how to do that?
Thanks in advance for your help, if something is not clear please let me know.
Regards,
Annalisa
Bookmarks