2

Am trying to print all console output messages to a QLabel or QTextBrowser. Does anyone know how to do this?

Thanks for any help,

CV

7
  • Do you have another library that you're trying to use with your Qt program that outputs to console?
    – jonsca
    Aug 12, 2011 at 15:08
  • Yes, A few libraries like OpenCV, Bullet.. They print messages to cout... and I want those messages into my QTextEdit widget
    – Chenna V
    Aug 12, 2011 at 18:01
  • Well, its not specifically OpenCV. If for example even if you take only a Qt application, and if a QObject::connect is not made properly, then it prints out message to the console saying that no SLOT was found or the receiver has no SLOT named "blablah"... So messages like these I want to capture. And am not sure what you mean by Qt is a C-based library, I know its a C++ based library but maybe you know something that I don't about Qt.
    – Chenna V
    Aug 12, 2011 at 20:19
  • I meant OpenCV and Bullet are C-based libraries, apologies for the confusion.
    – jonsca
    Aug 12, 2011 at 21:51
  • 1
    One of my coworkers solved the problem partially. He inherited a custom widget from QWidget and streambuffer, implemented overloaded functions. then redirected cout as "cout.rdbuf(widget->rdbuf())". This only prints all the cout messages in our code but not from other libraries. i.e. we still get any Qt messages in the console and not in our custom widget
    – Chenna V
    Aug 23, 2011 at 15:43

1 Answer 1

2

I found a solution at http://lists.trolltech.com/qt-interest/2005-06/thread00166-0.html that allows for a syntax like:

QDebugStream qout(std::cout, myTextEdit);
std::cout << "Send this to the Text Edit!" << endl;

I hope this will be useful for you. If it is not exactly what you mean, probably you can adapt it to your exact case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.