Qt宏定义函数举例
#include <QApplication>
#include <QFile>
#include <QTextStream>
#define LOG(text) \
QFile file(QApplication::applicationDirPath()+QDir::separator() \
+QString("log")+QDir::separator()+QString("%1.txt") \
.arg(QDate::currentDate().toString("yyyy-MM-dd"))); \
if (file.open(QIODevice::Append | QIODevice::Text)) { \
QTextStream out(&file); \
out << QString("[%1]: %2").arg(QDateTime::currentDateTime() \
.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(text) << '\n'; \
}
#define PRINT(text) \
qDebug() << text;
#define PRINT_TIME \
qDebug() << QString("-------------------------%1-------------------------") \
.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"));