Important: Please read the Qt Code of Conduct -

Browser geolocation doesn't work with QWebEngineView

  • I am novice to QT, and I have a task to implement simple desktop wrapper on QT for our website. Everything works well except for geolocation. Every time browser has to request permission for geolocation usage nothing is happened, geolocation doesn't work. I tried a few solutions from SO, this forum and other resources, but nothing helped me. Here is my code:

    #include <QLabel>
    #include <QWebEnginePage>
    class WebEnginePage: public QWebEnginePage{
        WebEnginePage(QObject *parent = Q_NULLPTR):QWebEnginePage(parent) {
            connect(this, &WebEnginePage::featurePermissionRequested, this, &WebEnginePage::onFeaturePermissionRequested);
        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[])
        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);;
        return app.exec();

    Could you give me some suggestions, what's wrong with my code?

Log in to reply