qml-webengineview二级页面不能打开问题

问题

在使用wenengineview嵌入网页的时候,如果网页中的链接默认在新窗口中打开,则点击后没有反应。

解决办法

文档中signals中有newViewRequested-signal(request)

  • signals文档:https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
    request文档:https://doc.qt.io/qt-5/qml-qtwebengine-webenginenewviewrequest.html
    request中包括要打开的URL,可以自己创建新窗口,或者修改原webengineview中的URL

  • 总结:主要就是根据信号中的URL参数自定义操作

  • demo
    webcontainer.qml

import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.9
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
import QtWebChannel 1.13

import WebDataComponent 1.0

WebEngineView {
    id: pluginWebContainer

    anchors.fill: parent

    width: parent.width
    height: parent.height

    settings.pluginsEnabled: true
    settings.screenCaptureEnabled: true
    settings.allowRunningInsecureContent: true

    settings.javascriptEnabled: true
    webChannel: WebChannel{
        registeredObjects: [_WebDataComponent]
    }

    onJavaScriptConsoleMessage: {
        console.log(message)
    }
    onLoadProgressChanged:
    {

    }

    onSmoothChanged: {

    }


    onCertificateError: {
        console.log(error)
    }

    onFeaturePermissionRequested: {
        if(feature  == WebEngineView.MediaAudioCapture
                || feature == WebEngineView.MediaAudioVideoCapture
                || feature ==  WebEngineView.MediaVideoCapture){

            grantFeaturePermission(securityOrigin,feature,true)

        } else{
            grantFeaturePermission(securityOrigin,feature,false)

        }
    }
    onUrlChanged: {
        console.log("url : "+url)
    }

    onNewViewRequested: {
        console.log(request.requestedUrl)
        url = request.requestedUrl
    }

    WebDataComponent{
        id:_WebDataComponent
        WebChannel.id:"bdlbscWebDataComponent"
    }
}



你可能感兴趣的:(qml-webengineview二级页面不能打开问题)