我的任务是为我们的网站在 QT 上实现简单的桌面包装器。除了地理位置,一切都很好。每次浏览器必须请求地理定位使用权限时,什么都没有发生,地理定位不起作用。我尝试了一些来自 SO 和其他资源的解决方案,但没有任何帮助。这是我的代码:
#include <QLabel>
#include <QWebEnginePage>
class WebEnginePage: public QWebEnginePage{
Q_OBJECT
public:
WebEnginePage(QObject *parent = Q_NULLPTR):QWebEnginePage(parent) {
connect(this, &WebEnginePage::featurePermissionRequested, this, &WebEnginePage::onFeaturePermissionRequested);
}
protected:
bool certificateError(const QWebEngineCertificateError &certificateError){
return true;
}
private Q_SLOTS:
void onFeaturePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature){
setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
}
};
#include <QApplication>
#include <QWebEngineView>
#include <QWebEngineSettings>
#include "main.moc"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setPage(new WebEnginePage());
QWebEngineSettings* settings = view.settings();
settings->setAttribute(QWebEngineSettings::WebAttribute::LocalStorageEnabled, true);
settings->setAttribute(QWebEngineSettings::WebAttribute::AllowGeolocationOnInsecureOrigins, true);
view.setUrl(QUrl(here is my url));
view.resize(1024, 750);
view.show();
return app.exec();
}
你能给我一些建议吗,我的代码有什么问题?