Hi everybody,
I'd like to know how to access either navigator or document objects from Qt-C++/Qt-QML. Just so simple as, i.e.: navigator.getUserMedia.
Hi everybody,
I'd like to know how to access either navigator or document objects from Qt-C++/Qt-QML. Just so simple as, i.e.: navigator.getUserMedia.
Both WebView and WebEngineView have appropriate APIs. Whether a particular call (e.g. getUserMedia()) is supported it is a different story.
Hi Wysota, thanks for responding so fast.
I'm interested in WebEngine. Do you know how to find out whether document or navigator are supported? I mean, what API should I use in order to access them, if accessing them is possible?
They are supported, it's a standard DOM API every browser needs to support.
yes, but what should I write. I mean what syntax should I use because if I call them via JavaScript embedded in the browser or via a .js file they do not exist.
The same as with any other browser.
javascript Code:
import QtQuick 2.4 import QtWebEngine 1.0 WebEngineView { width: 600 height: 300 Component.onCompleted: loadHtml("<html><body><p id='demo'></p><script>document.getElementById('demo').innerHTML = navigator.userAgent</script></body></html>") }To copy to clipboard, switch view to plain text mode
Hi Wysota, could you, please, also add the C++ code part corresponding to this .qml? Thanks in advance for your reply.
I added the following, but it does not show the window of WebEngineView in my main.qml.
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtWebEngine/qtwebengineglobal.h>
int main( int argc, char *argv[ ] )
{
QGuiApplication app( argc, argv );
QtWebEngine::initialize( );
QQmlApplicationEngine appEngine;
appEngine.load( QUrl( "qrc:/main.qml" ) );
return app.exec();
}
It means I have no need of a main.cpp?
This is my main.qml:
import QtQuick 2.4
import QtWebEngine 1.0
import QtQuick.Window 2.0
WebEngineView {
width: 1200
height: 900
visible: true
url: 'http://duckduckgo.com'
//Component.onCompleted: loadHtml( "<html><body><p id='demo'></p><script>document.getElementById('demo').innerHTM L = navigator.userAgent</script></body></html>" )
}
and this is my main.cpp:
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtWebEngine/qtwebengineglobal.h>
int main( int argc, char *argv[ ] )
{
QGuiApplication app( argc, argv );
QtWebEngine::initialize( );
QQmlApplicationEngine appEngine;
appEngine.load( QUrl( "qrc:/main.qml" ) );
return app.exec();
}
What's wrong? It doesn't show anything.
Bookmarks