qt - #define displayed output where it shouldn't -


i'm trying manage own debug system on qt have issues :

main.h

#include <qcoreapplication>  #include "phtools/phdebug.h"   int main(int argc, char *argv[]) {     // test of debug tool     debug << "test";      // test of timecode     for(int i=0; i<3;i++)     {         if(false)             debug << "problem me";     }     return 0; } 

phdebug.h

#ifndef phdebug_h #define phdebug_h  #include <qdebug> #include <qdate> #include <qrect>  #define debug phdebug d; d <<  phdebug  #define phdebug  qdebug() << __function__ << ":"  // in order rid of double quotes when displaying variable #define q(string) (string).tostdstring().c_str()  class phdebug { public:     qdebug operator<<(qdebug dbg)     {         qstring d;         d = qdate::currentdate().tostring("dd.mm.yyyy");         d += " - ";         d += qtime::currenttime().tostring("hh.mm.ss.zzz");         d += " in";         dbg << q(d);          return dbg;     }  };  #endif // phdebug_h 

so output should 04.09.2013 - 12.30.51.513 in main : test instead have :

04.09.2013 - 12.30.51.513 in main : test  04.09.2013 - 12.30.51.514 in main : problem me  04.09.2013 - 12.30.51.514 in main : problem me  04.09.2013 - 12.30.51.514 in main : problem me  

you problem lack of braces around if(false). d << phdebug part of macro still gets executed.

incidentally, qt has helper same thing q macro: qprintable


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -