How to use QML - QWebView in Android

自作多情 提交于 2019-12-10 23:05:26

问题


I want to deploy one YouTube application in Android. But it only works on my computer, and it does not work on Android. It does not load any video. The problem is only with the QWebView. I used a code similar to this: http://doc.qt.io/archives/qt-5.5/qtwebkitexamples-webkitqml-youtubeview-example.html


回答1:


Referring to Qt Documentations:

Qt WebEngine is not available on mobile platforms

While

Qt WebView is actually useful for mobile platforms! .. as stated by Qt Here

You can use QwebView with Android , This should be possible with Qt5.x, as follow:

Configure project for Android kit and add QT += webview to your .pro file.

In main.cpp, it's important to call QtWebView::initialize() right after creating the QGuiApplication:

#include <QtWebView>
QGuiApplication app(argc, argv);
QtWebView::initialize();

Now ready to use at qml side:

import QtWebView 1.1

WebView {
        id: webView
        anchors.fill: parent
        url: "http://some/url/"
        onLoadingChanged: {
            if (loadRequest.errorString)
                console.error(loadRequest.errorString);
        }
    }

Check Qt MiniBrowser Exmaple for QwebView with Android.




回答2:


if you are using Qt5. You should use WebEngineView, QWebView will not work on android.

import QtQuick 2.0
import QtWebEngine 1.4

Item{
    id:root
    height: 500
    width:  500

   Rectangle{
      anchors.fill: parent
      color: "black"

      WebEngineView{
         id : webEnginView
         anchors.fill: parent
         url : https://www.google.com
      }
   }
}


来源:https://stackoverflow.com/questions/48594113/how-to-use-qml-qwebview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!