views:

375

answers:

5

I'm making the transition from Eclipse CDT (with Qt integration plugin) to QtCreator 2.0 but there is still one thing that bother me with QtCreator :

When I debug in QtCreator, I don't see my qDebug messages inside the Application output tab until I stop the application I'm debugging... Then they are all displayed at once which is not very useful.

With Eclipse, I don't have this problem : the qDebug messages are displayed correctly when encountered while stepping through the source code.

I'm using both Eclipse CDT and Qt Creator under Windows. I didn't try under Linux (which is not an option right now).

Thanks.

+1  A: 

You don't have to close the application to see qDebug() messages.

There is a tab named 3 - Application output at the very bottom of the Qt Creator. Clicking that window will show you the Application output window at the bottom of Qt Creator.

That particular window will display the qDebug() messages as soon as they get called while the application is still running.

Hope it helps.

Edit:

I am not sure whether this is an answer but it might be a good valid cause.

From qDebug() documentation,

The Qt implementation of these functions prints the text to the stderr output under Unix/X11 and Mac OS X. With Windows, if it is a console application, the text is sent to console; otherwise, it is sent to the debugger.

Now Qt Creator doesn't have it's own debugger attached to it.

From Qt Creator documentation, we have to manually install the debugger. Since you are using Windows, you need to install Debugging tools for Windows manually.. More documentation can be found here...

Though am not used to Eclipse CDT, I assume there might be a Debugger attached to it and hence it displays the Debugging output correctly..

Since there isn't a Debugger attached to the Qt Creator, it might be behaving strangely..

Just give it a try..

liaK
Thanks for your answer but I do not see anything inside the Application output tab unless I stop the debugger. I have updated my question to be more accurate.
esavard
@esavard, Since you are into Windows, Do you have CDB (Microsoft Console Debugger) installed on your machine?
liaK
I use MinGW and not the Microsoft Compiler. MinGW comes bundled with Qt 4.6 and also the debugger (gdb). So, I didn't have to install anything. I had to build the Debugging Helper Library for Qt Creator though.
esavard
A: 

Have you tried to add the following line to your .pro?

OUTPUT += Console

Then you can output on std::cout.

Live
I see the std::cout outputs in Qt Creator Application output tab but not the qDebug message. If I could find a way to see both, It will be great.
esavard
A: 

This is a workaround, but you could probably install your own message handler. Take a look at qInstallMsgHandler in the documentation if you have not done so already.

I have a similar issue on Ubuntu 9.10 with Qt Creator 2.0 and Qt 4.7.0, though I don't see stdout output until the application is closed. It is as if the buffer isn't flushed. Printing to stderr shows the output in the Application output window immediately though.

fprintf(stderr, "Test1 \n"); // Prints immediately
fprintf(stderr, "Test2 \n\r"); // Prints immediately
fprintf(stdout, "Test3 \n"); // Delayed until app termination
fprintf(stdout, "Test4 \n\r"); // Delayed until app termination
qDebug() << "Test6 \n\r"; // Does not print at all
Fredrik H
A: 

Let me tell you something:

Once I have developed a c++ console application on linux. During running the application it was reading a file and starting to process some logic by printing out some status messages. When I run that application the output was OK. So for convenient debugging I have decided to run the application like this:

./a.out |& tee log

This command redirects standard output (may be also standard error I don't remember) into a file named "log". So when I run with this option I saw that it writes in the log file exactly the same as in std out only there are some displacements like this:

in std out - desired output

A
operation 1 success
B
operation 2 success
C
operation 3 success
D
operation 4 success

in the log file - output with displacement (this is not correct)

A
B
C
D
operation 1 success
operation 2 success
operation 3 success
operation 4 success

I guess your problem is this kind of one... I have taken a look at QDebug and have not seen any function that frees the buffer (something like operation called flush). So I recommend you to not waist your time on this kind of small issue (I also consider that Qt Creator 2.0 is release as a beta version and it may appear a bug) and use one of the following:

qFatal()
qCritical()
qWarning()
QMessageBox

I personally use QMessageBox::about in order to debug as you can stop the screan and read the value in a very usefull places that with debugger you can't (I mean you can but you can't see the current state of you GUI application as debugger have taken the control).

Hope helps.

Narek
+1  A: 

While not a complete answer, you can install DebugView (If you're on an XP machine) to view the qDebug output while you try to figure this out.

Another solution might be considered a hack, but works quite nicely, is to simply hijack debug messages yourself:

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <iostream>

void msgHandler( QtMsgType type, const char* msg )
{
    const char symbols[] = { 'I', 'E', '!', 'X' };
    QString output = QString("[%1] %2").arg( symbols[type] ).arg( msg );
    std::cerr << output.toStdString() << std::endl;
    if( type == QtFatalMsg ) abort();
}

int main(int argc, char *argv[])
{
    qInstallMsgHandler( msgHandler );
    QCoreApplication a(argc, argv);

    qDebug() << "Hello world.";
    qWarning() << "Uh, oh...";
    qCritical() << "Oh, noes!";
    qFatal( "AAAAAAAAAH!" );

    return a.exec();
}

Which would output:

[I] Hello world. 
[E] Uh, oh... 
[!] Oh, noes! 
[X] AAAAAAAAAH!

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

This is actually a modification of some code that I use myself to send qDebug, qWarning, etc., to a log file.

kurige
I do that already in my application. Can it be why I don't see the message in the debugger? I have DebugView, but, if I can do the debugging in Qt Creator without switching back and forth between the two applications, it is a better solution.
esavard
My mistake, I was using fprintf(stderr, ... instead of std::cerr. Work great now. Thanks.
esavard