Qt4 and Qt5 have different organization of header files. So I need to check the qt version to include different things, for example:
#if QT_VERSION >= 0x050000
#include <QtMultimedia>
#endif
however, this seems does not work. The QT_VERSION has not been defined. How can I solve this problem?
As soon as you include <QtGlobal>
you can check that with macros:
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
It's the same as @Javier suggested, just a different, more readable to me, syntax
As @Tay2510 commented, QT_VERSION
is declared inside of <QtGlobal>
. As a result, you must type #include <QtGlobal>
or another header that includes <QtGlobal>
, before the version dependent preprocessor directives.
<QObject>
and <QCoreApplication>
may also be used to access QT_VERSION
.
Here is an example of the code:
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QApplication>
#else
#include <QtGui/QApplication>
#endif
Remember that the qmake project should also handle version variations. Here are changes that should be done when using the QT multimedia library:
The .pro file should look something like:
QT += core gui
greaterThan(4, QT_MAJOR_VERSION): QT += widgets multimedia
lessThan(5, QT_MAJOR_VERSION): CONFIG += mobility
lessThan(5, QT_MAJOR_VERSION): MOBILITY += multimedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With