Search code examples
qtqt4qt5qwebview

QWebView on Qt4 and Qt5


I have a problem. I need to compile qt5 code on qt4. When I'm compiling it I have such error(on qt5 I haven't it):

QWebView: No Such File Or Directory

Here is my .pro file:

QT       += core gui xml webkitwidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = TPDetector
TEMPLATE = app


SOURCES += \
    main.cpp \
    mainwindow.cpp \
    VKAuth.cpp

HEADERS += \
    mainwindow.h \
    VKAuth.h

How I can build my project on qt4?


Solution

  • New webkit shipping with QT5 has a new structure. QWebView, QWebpage, etc. are now part of QtWebKitWidgets.

    So in your code you need to include webview like this:

      #include <QtWebKitWidgets/QWebView>
    

    and in your .pro file your need to add:

       QT += webkitwidgets
    

    If you really want to make your code forward/backwards compatible; I would just have a check for QT5:

       QT+= core gui webkit
    
       contains(QT_VERSION, ^5.*) {
           QT += webkitwidgets
       } 
       ...
    

    and then in your code:

      #if (QT_VERSION < 0x050000)
      #include <QWebView>
      #else 
      #include <QtWebKitWidgets/QWebView>
      #endif