使用Qt WebEngine自动授予对麦克风和摄像头的访问权限 [英] Auto Grant access to Mic and Camera with Qt WebEngine
问题描述
我正在使用RPi和WebRTC构建家庭安全系统.我只需要一种触发浏览器打开给定URL并自动授予对麦克风和摄像头访问权限的方法.我曾希望将WebEngine库与PyQt一起使用,但是Ry的PyQt不支持WebEngine.因此,我现在正在尝试Qt本身.不幸的是,我不熟悉C ++,所以我很挣扎.
I am building a home security system with RPi and WebRTC. I simply need a way to trigger a browser to open at a given URL and to auto-grant access to the Microphone and Camera. I had hoped to use the WebEngine library with PyQt but WebEngine is not supported in PyQt for RPi. So I am trying Qt itself now. Unfortunately I am not familiar with C++, so i am struggling.
示例此处有90我需要的百分比.该代码复制如下.我只需要调整它即可在需要时授予对麦克风和摄像头的访问权限.我希望有人可以帮助我吗?
The example here has 90% of what I need. The code is replicated below. I just need to tweak it to grant access to the mic and camera when it is requested. I am hoping someone can assist me with this?
#include <QApplication>
#include <QWebEngineView>
QUrl commandLineUrlArgument()
{
const QStringList args = QCoreApplication::arguments();
for (const QString &arg : args.mid(1)) {
if (!arg.startsWith(QLatin1Char('-')))
return QUrl::fromUserInput(arg);
}
return QUrl(QStringLiteral("https://www.qt.io"));
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(commandLineUrlArgument());
view.resize(1024, 750);
view.show();
return app.exec();
}
推荐答案
I answered this question but for PyQt5: Grant access to Cam & Mic using Python for PyQt WebEngine, I will only do a C ++ translation to Python, the base is the same.
#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);
}
};
QUrl commandLineUrlArgument()
{
const QStringList args = QCoreApplication::arguments();
for (const QString &arg : args.mid(1)) {
if (!arg.startsWith(QLatin1Char('-')))
return QUrl::fromUserInput(arg);
}
return QUrl(QStringLiteral("https://www.qt.io"));
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setPage(new WebEnginePage);
view.setUrl(commandLineUrlArgument());
view.resize(1024, 750);
view.show();
return app.exec();
}
#include "main.moc"
这篇关于使用Qt WebEngine自动授予对麦克风和摄像头的访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!