Best practices

Map and Scene view options

ArcGIS Maps SDK for Qt offers the three patterns listed below for creating and displaying a map in a map view, or scene in a scene view. For convenience, templates are included with the SDK to aid in creating new projects. In Qt Creator, choose the ArcGIS template based on your resources, platform, experience, and need for speed.

ArcGIS TemplateUses this APIMap view typeScene view typeRuns on Windows, Linux or macOSRuns on iOS or Android
Qt Quick Cpp appC++MapQuickViewSceneQuickViewYesYes
Qt Quick QML appQMLMapViewSceneViewYesYes
Qt Widgets Cpp appC++MapGraphicsViewSceneGraphicsViewYesNo

Qt Quick

ArcGIS Maps SDK for Qt supports writing Qt Quick apps in a combination of C++ and QML code, or in pure QML. This is accomplished by using the C++ API or its QML API, respectively.

Create a Qt Quick Cpp app

The MapQuickView class is part of the C++ API. MapQuickView is an implementation of MapView accessible from QML, and harnesses the speed of the C++ API in the business logic. With this approach, you leverage QML's extensive set of UI functionality, flexibility, and visual appeal while providing ArcGIS capabilities through the C++ API. Often recommended by Qt experts, this app pattern works on the platforms listed above. Note that with this template/pattern, you cannot use components of the C++ and QML APIs together in the same app.

To use this pattern, when creating your new project in Qt Creator, select Qt Quick C++ app (for the ArcGIS Maps SDK version installed) and then finish creating the project. The selected ArcGIS Maps SDK template registers MapQuickView type as MapView in main.cpp.

Use dark colors for code blocksCopy
  
1
2
    // Register the map view for QML
    qmlRegisterType<MapQuickView>("Esri.Display_map_quick_Cpp", 1, 0, "MapView");

In the C++ header file, the template creates a read/write Q_PROPERTY for the MapView.

Use dark colors for code blocksCopy
 
1
    Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged)

Additionally, in the C++ header file, the template includes the MapQuickView for the meta object compiler (MOC), since the type has been forward declared.

Use dark colors for code blocksCopy
 
1
    Q_MOC_INCLUDE("MapQuickView.h")

The template creates the MapView component in the <appname\>Form.qml file.

Use dark colors for code blocksCopy
                 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 Item {

    // Create MapView (MapQuickView) here. Then create its Map (type) etc., in C++ code.

    MapView {
        id: view
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true
    }

    // Declare the C++ instance which creates the map etc., and supply the view
    Display_a_map {
        id: model
        mapView: view
    }
}

In the your app's C++ code (<appname>.cpp), the template creates the following code. The constructor initializes QObject, and m_map using the BasemapStyle you selected when creating the project.

Use dark colors for code blocksCopy
     
1
2
3
4
5
Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
    QObject(parent),
    m_map(new Map(BasemapStyle::ArcGISStreets, this))
{
}

Below, the template creates the setMapView function. This function is what is executed when the MapView is created and set in QML code.

Use dark colors for code blocksCopy
             
1
2
3
4
5
6
7
8
9
10
11
12
13
// Set the view (created in QML)
void Display_a_map::setMapView(MapQuickView* mapView)
{
    if (!mapView || mapView == m_mapView)
    {
        return;
    }

    m_mapView = mapView;
    m_mapView->setMap(m_map);

    emit mapViewChanged();
}

Create a Qt Quick QML app

If you're familiar with the QML API from The Qt Company, you already know how quickly you can produce a powerful app with QML. QML offers a declarative, highly-readable syntax for designing and building responsive and fluid user interfaces for native desktop and mobile applications. ArcGIS Maps SDK for Qt extends QML with QML types that provide ArcGIS functionality. Objects are declared hierarchically and have bindable properties to provide automatically dynamic behavior. JavaScript functions are used to provide procedural code when needed. This is a powerful feature for developers who are familiar with web development and want to develop native apps. QML has been part of the API since version 10.2.5 and works on all supported platforms.

To use this pattern, when creating your new project in Qt Creator, select Qt Quick QML app (for the ArcGIS Maps SDK version installed) and then finish creating the project. The template creates the following code in main.qml. The template creates an ApplicationWindow containing a MapView. Within the MapView, the code declares a Map. BasemapStyle is set from your selection when creating the project.

Use dark colors for code blocksCopy
                   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "Display_a_map"

    // add a mapView component
    MapView {
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true

        // add a map to the mapview
        Map {
            // Add the ArcGISTopographic BasemapStyle to the map
            initBasemapStyle: Enums.BasemapStyleArcGISTopographic
        }
    }
}

Create a Qt Widgets Cpp app

C++ is all about performance. With the C++ API, you can build an app with a powerful computing back-end, and develop your UI in C++ using the Qt Widgets module. Qt Widgets has a rich suite of tools and components used for building powerful desktop applications. C++ is supported for applications running on Linux, macOS, and Windows. For pure C++ apps like these, the map view is implemented as a MapGraphicsView.

To use this pattern, when creating your new project in Qt Creator, select Qt Widgets app (for the ArcGIS Maps SDK version installed) and then finish creating the project. The template creates the following code in the <appname>.cpp file. BasemapStyle is set from your selection when creating the project.

Use dark colors for code blocksCopy
               
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Display_a_map::Display_a_map(QWidget* parent /*=nullptr*/):
    QMainWindow(parent)
{
    // Create a map using the ArcGISStreets BasemapStyle
    m_map = new Map(BasemapStyle::ArcGISStreets, this);

    // Create the Widget view
    m_mapView = new MapGraphicsView(this);

    // Set map to map view
    m_mapView->setMap(m_map);

    // set the mapView as the central widget
    setCentralWidget(m_mapView);
}

Integrate the SDK into an existing app

The ArcGIS Maps SDK for Qt can be integrated into an existing Qt app with a couple of steps. The steps vary slightly depending on if the application was created using Qt Quick or Qt Widgets.

Qt Quick C++ API integration

Integration with qmake

Include the arcgis_runtime_qml_cpp pri file into your project file. You can get this pri file from the SDK installation, under the folder sdk/ideintegration folder. For example, the following syntax includes the ArcGIS Maps SDK C++ API into your Qt Quick application:

Use dark colors for code blocksCopy
 
1
include(/pathToSDK/sdk/ideintegration/arcgis_runtime_qml_cpp.pri)

Qt Quick QML API integration

Integration with qmake

To use the QML API, include the arcgis_runtime_qml pri file into your project file. You can get this pri file from the SDK installation, under the folder sdk/ideintegration folder. For example, the following syntax includes the ArcGIS Maps SDK QML API into your Qt QML Quick application:

Use dark colors for code blocksCopy
 
1
include(/pathToSDK/sdk/ideintegration/arcgis_runtime_qml.pri)

Include the QML plugin in your app

After setting up your build system to find ArcGIS Maps SDK, you will need to add the paths of the QML plugins you plan on using into the QML Import Path. Because it contains all of the ArcGIS Maps SDK functionality for this API, add the path to the ArcGIS Maps SDK QML Plugin. Add QML plugins to the QML Import Path by using the QQmlEngine::addImportPath(pathToPlugin); method in C++ code. For example, you can add the ArcGIS Maps SDK QML plugin to the plugin path with the following syntax:

Use dark colors for code blocksCopy
 
1
view.engine()->addImportPath("pathToSDK/sdk/macOS/universal/qml");

As an alternative, you could instead add an environment variable called QML2_IMPORT_PATH with the paths to the various plugins you wish to use.

After the pri file is included and the import paths are added, import the QML plugin in a QML file by using the import syntax. For example:

Use dark colors for code blocksCopy
 
1
import Esri.ArcGISRuntime

Qt Widgets C++ API integration

Integration with qmake

Include the esri_runtime_qt project include file (pri) into your project file. You can get this pri file from the SDK installation, under the sdk/ideintegration folder. For example, the following syntax includes ArcGIS Maps SDK into your Qt Widgets application:

Use dark colors for code blocksCopy
 
1
include(/pathToSDK/sdk/ideintegration/esri_runtime_qt.pri)

Additional information

The following Qt resources provide additional information about how to include project files with qmake and how to add QML plugins into your applications.

Debugging your app

ArcGIS Maps SDK for Qt is built on top of the Qt Framework, which means you get access to all of the same debugging utilities used with Qt. Here are some helpful tips and tricks for debugging your Qt apps.

Using a web proxy

When debugging ArcGIS Maps SDK for Qt apps, a web debugging utility is often useful to capture and analyze the HTTP requests sent and responses returned. Fiddler and Charles are two examples of web debugging utilities used to perform this task. These tools can be used to debug an app by adding the following C++ code in your app: QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "127.0.0.1", 8888));. This code can be set at runtime, and can either be in your main.cpp, or in some other C++ class. Beyond using a proxy for debugging, QNetworkProxy::setApplicationProxy() can also be used to specify your organization's proxy server. To do this, specify the URL and port of your organization's proxy server. Find more information in Qt's QNetworkProxy documentation.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.