qt.permissions: Could not find permission plugin for QLocationPermission.
Solved
General and Desktop
-
Hi there,
I am developing application on MacOS with Qt 6.6.3 and I want to ask for location permission, however if I do so, I get this message in terminal output:
qt.permissions: Could not find permission plugin for QLocationPermission. Please make sure you have included the required usage description in your Info.plist
This is my code:
void TIIDialog::startLocationUpdate() { // ask for permission #if QT_CONFIG(permissions) QLocationPermission locationsPermission; locationsPermission.setAccuracy(QLocationPermission::Precise); locationsPermission.setAvailability(QLocationPermission::Always); switch (qApp->checkPermission(locationsPermission)) { case Qt::PermissionStatus::Undetermined: qApp->requestPermission(locationsPermission, this, []() { qDebug() << "permission request completed"; } ); qDebug() << "Undetermined"; return; case Qt::PermissionStatus::Denied: qDebug() << "Denied"; return; case Qt::PermissionStatus::Granted: qDebug() << "Granted"; break; // Proceed } #endif // start location update }
This is may Info.plist in the app bundle:
$ cat AbracaDABra.app/Contents/Info.plist <?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>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>AbracaDABra</string> <key>CFBundleGetInfoString</key> <string></string> <key>CFBundleIconFile</key> <string>appIcon.icns</string> <key>CFBundleIdentifier</key> <string></string> <key>CFBundleShortVersionString</key> <string></string> <key>CFBundleName</key> <string></string> <key>CFBundleShortVersionString</key> <string></string> <key>CFBundleVersion</key> <string>_</string> <key>CSResourcesFileMapped</key> <true/> <key>NSHumanReadableCopyright</key> <string>© 2019-2024 Petr Kopecký - MIT License</string> <key>NSPrincipalClass</key> <string>NSApplication</string> <key>NSHighResolutionCapable</key> <string>True</string> <key>LSMinimumSystemVersion</key> <string>$(MACOSX_DEPLOYMENT_TARGET)</string> <key>CFBundleAllowMixedLocalizations</key> <true/> <key>NSLocationUsageDescription</key> <string>AbracaDABra would like to access your location for trasmitters visualisation.</string> </dict> </plist>
And I have this in my CMakeLists.txt:
# Set a custom plist file for the app bundle if(APPLE AND APPLE_APP_BUNDLE) set_target_properties(${TARGET} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist.in MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}_${PROJECT_GIT_REV}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}" ) if (NOT CMAKE_GENERATOR STREQUAL "Xcode") # Need to sign application for location permissions to work add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND codesign -s - ${TARGET}.app) endif() endif(APPLE AND APPLE_APP_BUNDLE)
What am I doing wrong? Thank you!
-
OK, I will answer myself, I hope it helps others in future. In order to make the permissions work you need to have this in CMakeLists.txt (I did not need it so far):
## This is required for localization permissions to work if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(${TARGET}) endif()
-