Hi, Below is a macro I use for debugging. Before I put this in Wiki I thought I would post it here so that if it is useful, we will put it in wiki

Qt Code:
  1. // --- Debugging ---
  2. #include <QtDebug>
  3.  
  4. #define APP_NO_DEBUG_MESSAGES
  5.  
  6.  
  7. #if !defined( APP_NO_DEBUG_MESSAGES )
  8.  
  9. // Flags for Debug Output
  10. # define DEBUG_PRINT_FILEPATH
  11. # define DEBUG_PRINT_SHORT_FN_NAME
  12. # define DEBUG_PRINT_LINENUMBER
  13.  
  14. // Adjust Length of fields Here
  15. // FileName
  16. # define DEBUG_FILEPATH_LENGTH 27
  17. # define DEBUG_FILENAME_LENGTH 22
  18. // Function
  19. # define DEBUG_LONG_FUNCTION_LENGTH 40
  20. # define DEBUG_SHORT_FUNCTION_LENGTH 25
  21.  
  22. // LineNumber
  23. # define DEBUG_LINENUMBER_LENGTH 4
  24.  
  25. // file names
  26. # if defined( DEBUG_PRINT_FILEPATH )
  27. # define DEBUG_FILENAME ( QString( "%1").arg(__FILE__ , \
  28. -DEBUG_FILEPATH_LENGTH, QLatin1Char(' ')) )
  29.  
  30. # elif defined( DEBUG_PRINT_FILENAME )
  31. # include <QFileInfo>
  32. # define DEBUG_FILENAME ( QString( "%1").arg( \
  33. QFileInfo(__FILE__).fileName(), \
  34. -DEBUG_FILENAME_LENGTH, QLatin1Char(' ')) )
  35.  
  36. # elif defined( DEBUG_NO_FILENAME )
  37. # define DEBUG_FILENAME ""
  38. # else
  39. # error No debug file flags defined
  40. # endif
  41.  
  42. // function Names
  43. # if defined( Q_CC_GNU )
  44. # if defined ( DEBUG_PRINT_LONG_FN_NAME )
  45. # define DEBUG_FUNCTION_NAME QString( " %1").arg( __PRETTY_FUNCTION__, \
  46. -DEBUG_FULL_FUNCTION_LENGTH, QLatin1Char(' '))
  47. #
  48. # elif defined ( DEBUG_PRINT_SHORT_FN_NAME )
  49. # define DEBUG_FUNCTION_NAME QString( " %1").arg( __FUNCTION__ +QString("()"), \
  50. -DEBUG_SHORT_FUNCTION_LENGTH, QLatin1Char(' '))
  51. #
  52. # elif defined ( DEBUG_NO_FUNCTION_NAME )
  53. # define DEBUG_FUNCTION_NAME ""
  54. # else
  55. # error No debug fuction flags defined
  56. # endif
  57. # else
  58. # define DEBUG_FUNCTION_NAME ""
  59. # endif
  60.  
  61. // Line numbers
  62. # if defined ( DEBUG_PRINT_LINENUMBER )
  63. # define DEBUG_LINENUMBER ( QString("[%1]")\
  64. .arg( QString::number(__LINE__), DEBUG_LINENUMBER_LENGTH, QLatin1Char(' ')) )
  65. # else
  66. # define DEBUG_LINENUMBER ""
  67. # endif
  68.  
  69. // Debug Macro
  70. # define DEBUG() qDebug() << QString( DEBUG_FILENAME + DEBUG_LINENUMBER + DEBUG_FUNCTION_NAME + " :" )
  71. #else
  72. # define DEBUG() if(true);else qDebug()
  73. #endif
To copy to clipboard, switch view to plain text mode 

How do I use it
Qt Code:
  1. #include "Debug.h"
  2.  
  3. void foo(){
  4. DEBUG() << "Blah " << "Blah "
  5. }
To copy to clipboard, switch view to plain text mode