Minimal Map (QML)¶
The minimum code to display a map using Qt Quick.
Minimal Map demonstrates how to use the Map item to render a map. It shows the minimum amount of code needed to display the map, and can be used as a basis for further experimentation.
Running the Example¶
To run the example from Qt Creator , open the Welcome mode and select the example from Examples . For more information, visit Building and Running an Example.
C++ Code¶
In
main.cpp
we use only theQGuiApplication
andQQmlApplicationEngine
classes.In the main function, we first instantiate a
QGuiApplication
object. Then we create aQQmlApplicationEngine
and tell it to loadmain.qml
from the Qt Resource System .Finally,
exec()
launches the main event loop.
QML Code¶
In
main.qml
, we import the QtLocation QML module and its depending QtPositioning QML module. Next, we create the top level window, set a sensible default size, and make it visible. The window will be filled by a Map item showing the map.The Plugin item is necessary to define the map provider we are going to use. The example can work with any of the available geo services plugins. However, some plugins may require additional plugin parameters in order to function correctly and we can use PluginParameter to specify them. In this example, we use the
osm
plugin, which is a Qt Location Open Street Map Plugin and does not require any parameters.In the Map item, we refer to the
plugin
we use and we set thecenter
and thezoomLevel
of the map.
Requirements¶
The example requires a working internet connection to download
OpenStreetMap
map tiles. An optional system proxy should be picked up automatically.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.