summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/maps
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets/maps')
-rw-r--r--examples/webenginewidgets/maps/CMakeLists.txt23
-rw-r--r--examples/webenginewidgets/maps/Info.cmake.macos.plist33
-rw-r--r--examples/webenginewidgets/maps/doc/src/maps.qdoc20
-rw-r--r--examples/webenginewidgets/maps/mainwindow.cpp21
4 files changed, 76 insertions, 21 deletions
diff --git a/examples/webenginewidgets/maps/CMakeLists.txt b/examples/webenginewidgets/maps/CMakeLists.txt
index f6e6b94ea..93d9634f8 100644
--- a/examples/webenginewidgets/maps/CMakeLists.txt
+++ b/examples/webenginewidgets/maps/CMakeLists.txt
@@ -1,5 +1,5 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(maps LANGUAGES CXX)
@@ -22,6 +22,7 @@ qt_add_executable(maps
set_target_properties(maps PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
+ MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.examples.webenginewidgets.maps"
)
target_link_libraries(maps PUBLIC
@@ -30,6 +31,24 @@ target_link_libraries(maps PUBLIC
Qt::WebEngineWidgets
)
+if (APPLE)
+ set_target_properties(maps PROPERTIES
+ MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.cmake.macos.plist"
+ )
+
+ if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
+ # Need to sign application for location permissions to work
+ if(QT_FEATURE_debug_and_release)
+ set(exe_path "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/")
+ else()
+ unset(exe_path)
+ endif()
+ add_custom_command(TARGET maps
+ POST_BUILD COMMAND codesign --force -s - ${exe_path}maps.app
+ )
+ endif()
+endif()
+
install(TARGETS maps
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/webenginewidgets/maps/Info.cmake.macos.plist b/examples/webenginewidgets/maps/Info.cmake.macos.plist
new file mode 100644
index 000000000..82336b25a
--- /dev/null
+++ b/examples/webenginewidgets/maps/Info.cmake.macos.plist
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleName</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>NSSupportsAutomaticGraphicsSwitching</key>
+ <true/>
+ <key>NSLocationUsageDescription</key>
+ <string>The maps demo would like to access your location for demo purposes.</string>
+
+</dict>
+</plist>
diff --git a/examples/webenginewidgets/maps/doc/src/maps.qdoc b/examples/webenginewidgets/maps/doc/src/maps.qdoc
index 43728d081..f9bd19bfc 100644
--- a/examples/webenginewidgets/maps/doc/src/maps.qdoc
+++ b/examples/webenginewidgets/maps/doc/src/maps.qdoc
@@ -3,6 +3,7 @@
/*!
\example webenginewidgets/maps
+ \examplecategory {Web Technologies}
\title WebEngine Widgets Maps Example
\ingroup webengine-widgetexamples
\brief Demonstrates how to handle geolocation requests.
@@ -15,13 +16,19 @@
The \l {https://www.w3.org/TR/geolocation-API/}{Geolocation API} is a
JavaScript API that web applications can use to determine the user's
physical location to show on a map, for example. As \QWE relies on the
- \e {Qt Location} module to power this API, a viable location backend is
+ \e {Qt Positioning} module to power this API, a viable location backend is
needed for the target platform.
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.
+ \note On Windows 11, enable settings to grant the application access to
+ Windows location services. In the Settings App under
+ \uicontrol {Privacy & Security} > \uicontrol {Location}, enable \uicontrol
+ {Location services}, \uicontrol {Let apps access your location} and \uicontrol
+ {Let desktop apps access your location}.
+
\include examples-run.qdocinc
\section1 The Code
@@ -41,10 +48,10 @@
\printuntil setCentralWidget
We then proceed to connect a lambda function to the \l
- QWebEnginePage::featurePermissionRequested signal:
+ QWebEnginePage::permissionRequested signal:
\skipto m_view->page()
- \printuntil QWebEnginePage::Feature
+ \printuntil QWebEnginePermission permission
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
@@ -55,15 +62,14 @@
Now comes the part where we actually ask the user for permission:
- \printuntil securityOrigin
\printuntil });
Note that the question includes the host component of the web site's URI (\c
- securityOrigin) to inform the user as to exactly which web site will be
+ permission.origin()) to inform the user as to exactly which web site will be
receiving their location data.
- We use the \l QWebEnginePage::setFeaturePermission method to communicate the
- user's answer back to the web page.
+ We use the \l QWebEnginePermission::grant() and \l QWebEnginePermission::deny()
+ methods to communicate the user's answer back to the web page.
Finally we ask the \l QWebEnginePage to load the web page that might want to
use location services:
diff --git a/examples/webenginewidgets/maps/mainwindow.cpp b/examples/webenginewidgets/maps/mainwindow.cpp
index 0d2b49911..ca98ca263 100644
--- a/examples/webenginewidgets/maps/mainwindow.cpp
+++ b/examples/webenginewidgets/maps/mainwindow.cpp
@@ -13,25 +13,22 @@ MainWindow::MainWindow(QWidget *parent)
QWebEnginePage *page = m_view->page();
- connect(page, &QWebEnginePage::featurePermissionRequested,
- [this, page](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
- if (feature != QWebEnginePage::Geolocation)
+ connect(page, &QWebEnginePage::permissionRequested,
+ [this, page](QWebEnginePermission permission) {
+ if (permission.feature() != QWebEnginePermission::Geolocation)
return;
QMessageBox msgBox(this);
- msgBox.setText(tr("%1 wants to know your location").arg(securityOrigin.host()));
+ msgBox.setText(tr("%1 wants to know your location").arg(permission.origin().host()));
msgBox.setInformativeText(tr("Do you want to send your current location to this website?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
- if (msgBox.exec() == QMessageBox::Yes) {
- page->setFeaturePermission(
- securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
- } else {
- page->setFeaturePermission(
- securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
- }
+ if (msgBox.exec() == QMessageBox::Yes)
+ permission.grant();
+ else
+ permission.deny();
});
- page->load(QUrl(QStringLiteral("https://maps.google.com")));
+ page->load(QUrl(QStringLiteral("https://bing.com/maps")));
}