The minimum code to display a map using Qt Quick.
![]()
Minimal Map 演示如何使用 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.
要运行范例从 Qt Creator ,打开 欢迎 模式,然后选择范例从 范例 . For more information, visit Building and Running an Example.
在
main.cppwe use only theQGuiApplicationandQQmlApplicationEngine类。In the main function, we first instantiate a
QGuiApplicationobject. Then we create aQQmlApplicationEngineand tell it to loadmain.qml从 Qt 资源系统 .最后,
exec()launches the main event loop.
在
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.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
osmplugin, which is a Qt Location 开放式街道地图插件 and does not require any parameters.在 Map item, we refer to the
pluginwe use and we set thecenter和zoomLevelof the map.
The example requires a working internet connection to download
OpenStreetMapmap tiles. An optional system proxy should be picked up automatically.