Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWebView on Qt4 and Qt5

Tags:

qt

qt4

qt5

qwebview

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?

like image 785
user2090826 Avatar asked Oct 09 '13 20:10

user2090826


2 Answers

I had to add the libqtwebkit-dev package for my app to compile.

like image 105
Francois Botha Avatar answered Oct 26 '22 07:10

Francois Botha


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
like image 22
Aki Avatar answered Oct 26 '22 05:10

Aki