一:在.cpp或者.h文件中宏定义
#include <QApplication>
#include <QDebug>
#define HMI "hmi123"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug()<<HMI;
return a.exec();
}
在.cpp文件中定义,#define HMI "hmi123"
二:在.pro文件中宏定义
greaterThan(QT_MAJOR_VERSION, 4){
DEFINES += TR=\"QString::fromLocal8Bit\"
}else{
DEFINES += TR=\"tr\"
}
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug()<<TR("test");
return a.exec();
}
.pro文件中,DEFINES += TR="tr"和DEFINES += TR=“QString::fromLocal8Bit”
其中"字符是必不可少的,宏变量的值,为两个"中间的字符串tr 和QString::fromLocal8Bit
qt中一个全局的宏变量就定义成功了
上一篇:Qt开发之路41—使用QtConcurrent::run创建线程,有的线程无法启动的问题
下一篇:Qt开发之路43—Qt屏蔽qDebug调试信息