1

The project I'm working on might be developed in environments with Q4/5/5.6, this is causing some difficulties considering Qt's changes related to web kit (being used to show google maps via javascript interface).

I managed to laod the correct module in the project file by doing:

greaterThan(QT_MAJOR_VERSION, 4) {
    greaterThan(QT_MINOR_VERSION, 5) {
        message("Qt5.6")
        QT += widgets webenginewidgets #include <QtWebEngineWidgets> for Qt5.6 in map.cpp
    } else {
        message("Qt5")
        QT += widgets webkitwidgets #include <QtWebKitWidgets> for Qt5 in map.cpp
    }
} else {
    message("Qt4")
  QT += webkit #include <QtWebKit> for Qt4 in map.cpp
}

The problem is that each module has a different #include:

#include QtWebKit           // for Qt4
#include QtWebKitWidgets    // for Qt5 lower then 5.6
#include QtWebEngineWidgets // for Qt5.6

Is it possible to make code portable so that it can discover which #include should be performed?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136

1 Answers1

1

You can use something like

#include <QtGlobal>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
#include <QtWebEngineWidgets>
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWebKitWidgets>
#else
...
#endif
peppe
  • 21,934
  • 4
  • 55
  • 70