其他分享
首页 > 其他分享> > QWebEngine自动添加麦克风和摄像头权限

QWebEngine自动添加麦克风和摄像头权限

作者:互联网

 

#include <QApplication>
#include <QUrl>
#include <QWebEngineView>

class WebEnginePage: public QWebEnginePage{
    Q_OBJECT
public:
    WebEnginePage(QObject *parent = Q_NULLPTR):QWebEnginePage(parent){
        connect(this, &WebEnginePage::featurePermissionRequested, this, &WebEnginePage::onFeaturePermissionRequested);
    }
private Q_SLOTS:
    void onFeaturePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature){

        if(feature  == QWebEnginePage::MediaAudioCapture
                || feature == QWebEnginePage::MediaVideoCapture
                || feature == QWebEnginePage::MediaAudioVideoCapture)
            setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
        else
            setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
    }
};

int main(int argc, char *argv[]) { QApplication app(argc, argv); QWebEngineView view; view.setPage(new WebEnginePage); view.setUrl(QUrl("https://baidu.com")); view.show(); return app.exec(); }

 

参考于:使用Qt WebEngine自动授予对Mic和Camera的访问权限 - Thinbug

标签:麦克风,WebEnginePage,QWebEnginePage,QWebEngine,feature,securityOrigin,include,摄像头,v
来源: https://www.cnblogs.com/tingtaishou/p/15117636.html