How can I see qDebug messages while debugging in QtCreator

前端 未结 7 1451
感动是毒
感动是毒 2021-02-04 06:38

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 Qt

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 07:16

    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.

提交回复
热议问题