I made a project in Qt and added a QWebview to it then I added Qt += webkit
to the .pro
file. However, upon compiling, I get these to errors:
...ui_mainwindow.h:42: error: undefined reference to `_imp___ZN8QWebViewC1EP7QWidget'
...ui_mainwindow.h:45: error: undefined reference to `_imp___ZN8QWebView6setUrlERK4QUrl'
The errors refer to here (in ui_mainwindow.h
):
...
webView = new QWebView(centralWidget); // <-- First error here
webView->setObjectName(QStringLiteral("webView"));
webView->setGeometry(QRect(0, 0, 300, 200));
webView->setUrl(QUrl(QStringLiteral("about:blank"))); // <-- Second error here
MainWindow->setCentralWidget(centralWidget);
...
In Program.pro:
QT += core gui webkit
I think those errors usually occur without Qt += webkit
, but in this case that's not what's happening.
...ui_mainwindow.h:42: error: undefined reference to `_imp___ZN8QWebViewC1EP7QWidget'
The linker does not find the the webview widget symbol.
I think those errors usually occur without Qt += webkit, but in this case that's not what's happening.
That is correct, however the QtWebkit module was split into webkit and webkitwidgets in Qt 5 because the widgets were moved usually into their separate module in Qt 5 since the way of building UIs is QtQuick as promoted.
To fix this, you would need to write this in your project file:
QT = webkit webkitwidgets
Note that it is unnecessary to use the core
and gui
modules explicitly since they are added by default. Also, make sure you have the webkitwidgets module installed, too, otherwise even the above will not be enough.