WebEngine Widgets Maps Example#
Demonstrates how to handle geolocation requests.
Maps demonstrates how to handle geolocation requests originating from a
To avoid accidentally sending location information to third parties geolocation requests are denied by default. This example demonstrates the steps an application must take in order to start accepting these requests.
On Windows 11, enable settings to grant the application access to Windows location services. In the Settings App under Privacy & Security > Location, enable Location services, Let apps access your location and Let desktop apps access your location.
Running the Example#
The example program consists of a single class,
MainWindow, inheriting from
In the constructor we first set up the
QWebEngineView as the central widget:
We then proceed to connect a lambda function to the
This signal is emitted whenever a web page requests to make use of a certain feature or device, including not only location services but also audio capture devices or mouse locking, for example. In this example we only handle requests for location services:
Now comes the part where we actually ask the user for permission:
Note that the question includes the host component of the web site’s URI (
securityOrigin) to inform the user as to exactly which web site will be receiving their location data.
We use the
setFeaturePermission method to communicate the user’s answer back to the web page.
Finally we ask the
QWebEnginePage to load the web page that might want to use location services: