|
MapLibre Native for Qt
|
MapLibre Native can be used with Qt either with C++ or with QML. The following sections will guide you through the process of setting up a project and using MapLibre Native with it.
Two example apps are provided for Qt 6 in the examples directory of the repository:
quick is a QML app that uses the MapView QML type.widgets is a C++ app that uses the QMapLibre::GLWidget widget.or alternatively
To use MapLibre Native in a Qt project built with CMake you can use the find_package command to locate the package QMapLibre and then link the target to the QMapLibre::Core, QMapLibre::Location or QMapLibre::Widgets targets. Only specific components can be looked for by using the COMPONENTS option. For example, to use the Widgets component you need to add the following lines to your CMakeLists.txt:
There are multiple options to make CMake find the package:
QMapLibre_DIR variable to the directory where the package is installed ending with <path>/lib/cmake/QMapLibreCMAKE_PREFIX_PATH variable to the directory where the package is installedNo special additional setup is needed. QMapLibre and QMapLibreWidgets libraries need to be provided with your application.
To use MapLibre Native in a QML project you need to ensure that the plugins are installed with your application:
plugins/geoservices for the mapping engine itselfqml/MapLibre for the QML typesOf course also QMapLibre and QMapLibreLocation libraries need to be provided with your application.
This can be ensured automatically using the helper function qmaplibre_location_setup_plugins(<target>) which is available once MapLibre Native is found by CMake.
For example, to use MapLibre in a CMake-based QML project you need to add
Once your application is deployed there should be no special environment or other overrides needed to run the application. However, during development you may need to set some environment variables:
QSG_RHI_BACKEND=opengl to force the OpenGL backendDYLD_LIBRARY_PATH to find libraries on macOSLD_LIBRARY_PATH to find libraries on LinuxQML_IMPORT_PATH=<installation-path>/qml to find the QML types (QML2_IMPORT_PATH for Qt 5)QT_PLUGIN_PATH=<installation-path>plugins to find the pluginsFor Android multi-ABI builds you need to ensure that the correct build is picked-up. In CMake this can be done like