You can't. The QML WebView element doesn't have a public C++ API. You have two ways to work around this:
- Use private API. First, add this to the .pro file:
QT += quick quick-private webkit-private
Then include the private headers:
#include <private/qquickwebview_p.h>
Now you can access the WebView, as long as you get a pointer to it (for example by using QObject::findChildren
or by passing the QObject*
from QML to C++. Here I simply assume the WebView is the root object, for simplicity):
QQuickWebView * webView = dynamic_cast<QQuickWebView*>(viewer.rootObject());
qDebug() << webView->url();
- Use the generic
QObject
API to access the WebView's properties:
QObject * webView = viewer.rootObject();
qDebug() << webView->property("url");