Results 1 to 6 of 6

Thread: Clarification on how to use Qt's debugging techniques

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Clarification on how to use Qt's debugging techniques

    I've just read http://doc.trolltech.com/4.6/debug.html and want to make sure that I understand it properly.

    Is it correct to say that qDebug(), qWarning() and the debugging macros are used for debugging during development, and can be compiled to nothing for a release build... but qCritical() and qFatal() are used for reporting runtime errors during normal use (e.g. lost connection to a remote server)?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Clarification on how to use Qt's debugging techniques

    Quote Originally Posted by hackerNovitiate View Post
    I've just read http://doc.trolltech.com/4.6/debug.html and want to make sure that I understand it properly.

    Is it correct to say that qDebug(), qWarning() and the debugging macros are used for debugging during development, and can be compiled to nothing for a release build...
    Yes

    but qCritical() and qFatal() are used for reporting runtime errors during normal use (e.g. lost connection to a remote server)?
    Never, ever, not once in your lifetime, use those or asserts in production software! I do horrible things to you if I use a program of you and it crashes without any reason or it doesn't report the errors correctly. A lost connection is NO reason to create those two debug messages or even an assert. You should handle those errors gracefully.

    Only use runtime debugging when developing your software. You can build your program to activate runtime debugging in a release build to create a log or something else so you can debug on the target machine too by setting a variable or clicking a checkbox. But don't use debugging already activated in production software.

  3. The following user says thank you to tbscope for this useful post:

    hackerNovitiate (20th June 2010)

  4. #3
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clarification on how to use Qt's debugging techniques

    Quote Originally Posted by tbscope View Post
    Never, ever, not once in your lifetime, use those or asserts in production software! I do horrible things to you if I use a program of you and it crashes without any reason or it doesn't report the errors correctly.
    Urgency noted! I found out later that qFatal() forces an abort and a core dump. At first I thought qCritcal() and qFatal() were for release-build debugging because they don't get compiled away, but now I gathered that the QDebug family is for developmental debugging only.

    You can build your program to activate runtime debugging in a release build to create a log or something else so you can debug on the target machine too by setting a variable or clicking a checkbox.
    Hmm... so if debugging were enabled on a release build, should I use a generic QTextStream to write to a file, or is there something else that is designed for release-build debugging?

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Clarification on how to use Qt's debugging techniques

    You can redirect qDebug() output to a file.
    QDebug::QDebug ( QIODevice * device )

    This means that you can construct a different debug stream depending on the type of executable. When in debug mode write to stderr/stdout or console and when in release mode, write to a file for example.

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clarification on how to use Qt's debugging techniques

    qCritcal() and qFatal() and for exactly what they say. If some critical occurs in your app and you can't recover from it graciously (for example, a memory allocation fails and trying to create a dialog to inform the user also fails, or you notice memory corruption and can no longer depend on the integration of your application), then you can use them to shutdown your app before anything gets worse. For most errors (such as lost connection to a server) you should just inform the user and recover.

  7. The following user says thank you to squidge for this useful post:

    hackerNovitiate (21st June 2010)

  8. #6
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clarification on how to use Qt's debugging techniques

    Thanks, tbscopde and fatjuicymole. It's all much clearer now.

    Part of my confusion was because I got QT_NO_DEBUG and QT_NO_DEBUG_OUTPUT mixed up. The former is defined in Qt Creator's makefile.release, so I thought a release build automatically suppress debug (and warning) messages.

Similar Threads

  1. debugging qt
    By freekill in forum Newbie
    Replies: 4
    Last Post: 26th November 2009, 05:21
  2. Replies: 0
    Last Post: 21st September 2009, 17:25
  3. Clarification about dataChanged
    By airbites in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 16:02
  4. need some clarification on QImage and QRgb usage
    By kona in forum Qt Programming
    Replies: 5
    Last Post: 6th September 2008, 14:20
  5. Debugging with gdb
    By SteM in forum Newbie
    Replies: 4
    Last Post: 9th August 2007, 14:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.