【问题标题】:Qt (qml): Access Bundle file in Qt for Webview Url in ios?Qt (qml):在 Qt 中为 iOS 中的 Webview Url 访问 Bundle 文件?
【发布时间】:2018-03-14 03:10:19
【问题描述】:

由于我是 Qt ios 开发的新手,我不知道将捆绑数据文件称为 Webview 的 url。

注意:: Webview 不支持 url 的资源系统。

qt minibrwoser 为例进行实施。

    Update in .pro file, Added html_file folder as Bundle data:

    ios {
    deployment.files = $${PWD}\\html
    deployment.path =
    QMAKE_BUNDLE_DATA += deployment
    }

Update in main.qml file
 WebView {
        id: webView
        anchors.fill: parent
        url: "file:assets-library:/assest/html/view.html" 

//url didn't load on runtime (not sure how to access bundle data html file at runtime)

        onLoadingChanged: {
            if (loadRequest.errorString)
                console.error(loadRequest.errorString);
        }
    }

我可以通过以下代码更新访问 android 中的同一页面:

  WebView {
        id: webView
        anchors.fill: parent
        url: "file:///android_asset/html/view.html"
        onLoadingChanged: {
            if (loadRequest.errorString)
                console.error(loadRequest.errorString);
        }
    }

问题::如何在ios中调用bundle_data文件作为url?

如果有人遇到类似问题并知道解决方案。请指导我解决。

【问题讨论】:

    标签: c++ ios qt qml qwebview


    【解决方案1】:

    使用QCoreApplication::applicationDirPath()可以获取可执行文件的路径和可执行文件的内容项。

    在 main.qml 中添加以下内容

    #include<QCoreApplication>
    
    
    initialUrl="file:/" + QCoreApplication::applicationDirPath() + "/html/view.html"
    
     context->setContextProperty(QStringLiteral("initialUrl"),
                                    Utils::fromUserInput(initialUrl));
    

    参考::http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath

    WebView {
            id: webView
            anchors.fill: parent
            url: initialUrl
    
    //url didn't load on runtime (not sure how to access bundle data html file at runtime)
    
            onLoadingChanged: {
                if (loadRequest.errorString)
                    console.error(loadRequest.errorString);
            }
        }
    

    参考::https://forum.qt.io/topic/67214/path-to-image-in-xcassets-folder-ios/2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多