Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Browser geolocation doesn't work with QWebEngineView
Forum Updated to NodeBB v4.3 + New Features

Browser geolocation doesn't work with QWebEngineView

Scheduled Pinned Locked Moved Unsolved QtWebEngine
1 Posts 1 Posters 249 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Protagor
    wrote on last edited by
    #1

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

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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved