QT QML QtWebEngine 打开摄像头

qml 代码 index.qml

import QtQuick 2.0

import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.7
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11

ApplicationWindow {
    id: window
    visible: true
    width: 800
    height: 600
    title: qsTr("WebEngineAction Example")

    WebEngineView {
        id: webEngineView
        // 网页路径
        url: "file:///Users/maohuawei/project/webrtc/webrtc-web/step-02/index.html"  //"file:///Users/maohuawei/project/webrtc/webrtc-web/myapp/index.html"
        anchors.fill: parent
        settings.pluginsEnabled: true
        settings.screenCaptureEnabled: true
        //AllowRunningInsecureContent
        settings.allowRunningInsecureContent: true

        settings.javascriptEnabled: true

        onFeaturePermissionRequested: {

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


                grantFeaturePermission(securityOrigin,feature,true)

            } else{
                grantFeaturePermission(securityOrigin,feature,false)

            }
        }
    }
}

main.cpp

#include 
#include 
#include 


int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("QtExamples");
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QtWebEngine::initialize();



    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/index.qml")));

    return app.exec();
}

解决方案

WebEngineView 里面的

    onFeaturePermissionRequested: {

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


            grantFeaturePermission(securityOrigin,feature,true)

        } else{
            grantFeaturePermission(securityOrigin,feature,false)

        }
    }

你可能感兴趣的:(QT)