QWebView on Qt4 and Qt5

I have a problem. I need to compile qt5 code on qt4. When I compile it, I have such an error (on qt5 I do not have 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 can I build my project on qt4?

+6
source share
2 answers

The new webkit delivery with QT5 has a new structure. QWebView, QWebpage, etc. Now included in QtWebKitWidgets.

So, in your code, you need to enable webview as follows:

  #include <QtWebKitWidgets/QWebView> 

and in your .pro file you need to add:

  QT += webkitwidgets 

If you really want to make your code forward / backward compatible; I would just check out 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 
+8
source

I had to add the libqtwebkit-dev package for my compilation application.

+10
source

Source: https://habr.com/ru/post/955623/


All Articles