×
Namespaces

Variants
Actions

Simple MACROs To Help With Debug Messages

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Emulator / Nokia N97 Mini
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: QDebug
Created: skumar_rao (21 Nov 2010)
Last edited: hamishwillee (11 Oct 2012)

If your project involves in lots of message transaction and more then one executable involved like server - client type of application. It might not help if you just have the Qt Creators Device debug capability. You need to monitor the out put as your applications run on device, for that we can use the qDebug() etc but sometimes the formating of the output message might be a hard work.

So below macros try to help in that.

Before you use qDebug() you need to include the

#include <QDebug> where you want to use

Contents

Macro

#define DEBUG(x) qDebug() << x;

How to use

DEBUG("Example: Debug with out tag");

Out Put

Example: Debug with out tag

Macro

#define DEBUG_TAG(tag, x) qDebug() << "[" << tag << "]" << x;

How to use

DEBUG_TAG("Example:", "Debug with tag");

Out Put

[ Example: ] Debug with out tag

Macro

 #define WARNING(x) qWarning() << x;

How to use

WARNING("Example: Warning with out tag");

Out Put

Example: Warning with out tag

Macro

#define WARNING_TAG(tag, x) qWarning() << "[" << tag << "]" << x;

How to use

WARNING_TAG("Example:", "Warning with tag");

Out Put

[ Example: ] Warning with tag

Macro

#define VERBOSE(x) qDebug() << x;

How to use

VERBOSE("Example: Verbose with out tag");

Out Put

Example: Verbose with out tag

Macro

#define VERBOSE_TAG(tag, x) qDebug() << "[" << tag << "]" << "(verbose)" x;

How to use

VERBOSE_TAG("Example:", "Verbose with tag");

Out Put

[ Example: ] (verbose)Verbose with tag

some more variants

#define DEBUG(exp) qDebug() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << exp << ")"

//( ..\DebugMacroExamples\widget.cpp : 51 ) ( Example: A Example Expression )
 
#define DEBUG_TAG(tag, exp) qDebug() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << tag << ")" << \
"(" << exp << ")"

 
//( ..\DebugMacroExamples\widget.cpp : 52 ) ( Example: ) ( A Example Expression )
 
#define CRITICAL(exp) qCritical() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << exp << ")"

 
// ( ..\DebugMacroExamples\widget.cpp : 56 ) ( Example: A Example Expression )
 
#define CRITICAL_TAG(tag, exp) qCritical() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << tag << ")" << \
"(" << exp << ")"

 
// ( ..\DebugMacroExamples\widget.cpp : 58 ) ( Example: ) ( A Example Expression )
 
#define WARNING(exp) qWarning() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << exp << ")"

 
// ( ..\DebugMacroExamples\widget.cpp : 60 ) ( Example: A Example Expression )
 
#define WARNING_TAG(tag, exp) qWarning() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"(" << tag << ")" << \
"(" << exp << ")"

 
// ( ..\DebugMacroExamples\widget.cpp : 60 ) ( Example: ) ( A Example Expression )
 
#define DEBUG_ENTER_FN() qDebug() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"( enter )" << \
"(" << __FUNCTION__ << ")"

 
// ( ..\DebugMacroExamples\widget.cpp : 62 ) ( enter ) ( Widget )
 
#define DEBUG_EXIT_FN() qDebug() << "("<< __FILE__ << ":" << __LINE__ << ")" << \
"( exit )" << \
"(" << __FUNCTION__ << ")"

 
//( ..\DebugMacroExamples\widget.cpp : 64 ) ( exit ) ( Widget )
This page was last modified on 11 October 2012, at 04:18.
59 page views in the last 30 days.