我正试图在Debug system
上管理自己的Qt
,但我遇到了一些问题:
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 with 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 to get rid of double quotes when displaying a 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
所以输出应该是04.09.2013 - 12.30.51.513 in main : Test
,但我有这个:
04.09.2013 - 12.30.51.513 in main : Test
04.09.2013 - 12.30.51.514 in main : problem with me
04.09.2013 - 12.30.51.514 in main : problem with me
04.09.2013 - 12.30.51.514 in main : problem with me
答案 0 :(得分:1)
问题是if(false)
周围缺少大括号。您的宏的d << PHDEBUG
部分仍然会被执行。
顺便说一下,Qt已经有了一个与你的Q宏做同样事情的助手:qPrintable