兼容 Qt4 和 Qt5 技巧

Author Avatar
Mutse Young 3月 28, 2013

如何编写兼容Qt4和Qt5的程序?

工程文件pro

在pro文件中增加

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

源文件

在源文件中使用宏条件编译,如:

1
2
3
4
5
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtGui>
#else
#include <QtWidgets>
#endif