Call C++ method from a javascript (html) loaded on QtWebView (android)
-
Hi All,
Have any way to call C++ method from a javascript on a page, in QtWebView (android)
I want develop my UI in html5, load it on QtWebView , and buttons on my html (javascript) fire native code in c++ (e.g: start camera);
Or fire some QML that will fire native C++ code. Or any other way?
Have any way to achieve this?
And what is Qt WebEngine?
I am using QT 5.4
Thanks for help
-
Hi,
bq. Have any way to call C++ method from a javascript on a page, in QtWebView (android)
Yes. Check out "addToJavaScriptWindowObject":http://doc.qt.io/qt-5/qwebframe.html#addToJavaScriptWindowObject. Just declare the functions as public slots. An example "here":http://doc.qt.io/qt-5/qtwebkitexamples-webkitwidgets-imageanalyzer-example.html.
bq. Or fire some QML that will fire native C++ code. Or any other way?
QML would be completely different approach than using QtWebkit.
For detailed exaplantion of interaction of C++ and QML, check "qtqml-cppintegration":http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html.bq. And what is Qt WebEngine?
Its a new web rendering engine that is planned to replace QtWebKit in Qt. It is based upon Google Chromium browser.
-
[quote author="re.tf" date="1422286520"]
Have any way to call C++ method from a javascript on a page, in QtWebView (android)[/quote]i doubt that this is possible. Since QtWebView module is just a wrapper for the mobile platform's native web view. And there is no way to "communicate":https://qt.gitorious.org/qt/qtwebview/source/ea443a6960316d5070c1a3a5dbe21037a96ff7e4:src/imports/plugins.qmltypes#L4 very much with this view (yet).
-
[quote author="raven-worx" date="1422346835"][quote author="re.tf" date="1422286520"]
Have any way to call C++ method from a javascript on a page, in QtWebView (android)[/quote]i doubt that this is possible. Since QtWebView module is just a wrapper for the mobile platform's native web view. And there is no way to "communicate":https://qt.gitorious.org/qt/qtwebview/source/ea443a6960316d5070c1a3a5dbe21037a96ff7e4:src/imports/plugins.qmltypes#L4 very much with this view (yet).
[/quote]
Ahh.. Right. That method wont work on android as it is QWebView based and it is not supported on Android. Sorry for that. Even "QtWebEngine":http://qt-project.org/wiki/QtWebEngine#5405d8a903c83e89cb649f1b518ef1be won't be of use.
-
Well, i need this to build integration between html5 and C++. Any other workaround?
For sample, in case of instagram, I think that all UI is HTML5 and when you click in camera it fire camera in native way.
This is true?
How instagram achieve this?I thought that 'Instagram' was build in QT! Not?
-
May be "Qt WebChannel":http://doc.qt.io/qt-5/qtwebchannel-index.html. This "article":http://www.kdab.com/qt-webchannel-bridging-gap-cqml-web/ is a good read.