【问题标题】:How to use QML - QWebView in Android如何在 Android 中使用 QML - QWebView
【发布时间】:2018-08-09 21:42:26
【问题描述】:

我想在 Android 中部署一个 YouTube 应用程序。但它只适用于我的电脑,不适用于Android。它不加载任何视频。 问题仅在于 QWebView。我使用了类似这样的代码:http://doc.qt.io/archives/qt-5.5/qtwebkitexamples-webkitqml-youtubeview-example.html

【问题讨论】:

    标签: android qt qml qwebview


    【解决方案1】:

    参考 Qt 文档:

    Qt WebEngine 在移动平台上不可用

    虽然

    Qt WebView 实际上对移动平台很有用! .. as stated by Qt Here

    您可以将QwebViewAndroid 一起使用,这应该可以与Qt5.x 一起使用,如下所示:

    为 Android 套件配置项目并将 QT += webview 添加到您的 .pro 文件中。

    main.cpp 中,重要的是在创建QGuiApplication 后立即调用QtWebView::initialize()

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

    现在可以在 qml 端使用:

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

    Android检查Qt MiniBrowser Exmaple的QwebView。

    【讨论】:

    • @Carlos Duarte,请注意,我认为第一个答案让您感到困惑……事实恰恰相反。 Qt WebEngineView 仅适用于 Qt for MSVS/Chromium .. 而 QwebView 确实适用于 Android,请检查 Qt WebView Qt5.10
    【解决方案2】:

    如果您使用的是 Qt5。您应该使用 WebEngineView,QWebView 将无法在 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
          }
       }
    }
    

    【讨论】:

    • 了解更多详情here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2016-03-13
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    相关资源
    最近更新 更多