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(); }