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

Chenna V
  • 10,185
  • 11
  • 77
  • 104
  • Do you have another library that you're trying to use with your Qt program that outputs to console? – jonsca Aug 12 '11 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 '11 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 '11 at 20:19
  • I meant OpenCV and *Bullet* are C-based libraries, apologies for the confusion. – jonsca Aug 12 '11 at 21:51
  • Here's another question, because the solution I gave may not be able to accommodate the GUI elements -- do you need your end user to see the specific messages, or are you just using them for debugging? If you just need them for debugging, you could use the procedure I outlined below, but dump them to a file... – jonsca Aug 12 '11 at 22:25
  • Did you figure out a way to dump the messages you wanted? – jonsca Aug 22 '11 at 04:47
  • 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 '11 at 15:43

1 Answers1

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.

robermorales
  • 3,293
  • 2
  • 27
  • 36