QML error: Unable to assign MapQuickView to QMLMapView

1395
6
Jump to solution
07-17-2018 04:11 PM
WayneGuidry
New Contributor III

I used the ESRI template to create a basic QML/C++ Test app to learn QML. I wanted to then experiment adding my own custom scale bar to the map (I'm using Runtime 100.1 with QT 5.8) and was attempting to follow the guidance in: https://community.esri.com/thread/201990-scale-bar.

I created the scale bar; however, when I attempt to assign it from my main qml file when its running I receive the error: "Unable to assign ESRI::ArcGISRuntime::MapQuickView to QMLMapView" at the map:mapview line below.

The main QML looks like:

import QtQuick 2.6

import QtQuick.Controls 1.4

import Esri.Test 1.0

Test{

   width:800

   height:600

   MapView{

        id:mapview

        anchors.fill: parent

        objectName: "mapView"

      ScaleBar{

           map:mapview

      }

   }

}

I've googled the error and looked over ESRI forums, but don't see any mention of this error.

No code was changed from the sample on the C++ side or the scale bar itself. What am I missing?

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

The issue is that there is a mixture of our QML and C++ APIs in your example. We have one API which is purely QML, and that is the API that AppStudio uses. You can tell if you are using the QML API because you will see "import Esri.ArcGISRuntime 100.x" in the code - this is the QML plugin we build and ship. If you instead want to use our C++ API, you can utilize the MapQuickView to expose the MapView to QML, and write your business logic in C++ and your UI in QML. The different development paradigms are highlighted in this doc - Qt SDK best practices—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

Long story short - if you create a new project and select the "ArcGIS Runtime Qt Quick QML" template, everything should work. If you prefer to use the C++ API, there will be more work involved - for starters, you will need to remove the "import Esri.ArcGISRuntime 100.x" from your ScaleBar.qml, expose the various Q_PROPERTYs that you need, etc.

View solution in original post

0 Kudos
6 Replies
TroyFoster
Occasional Contributor

I just tried the sample on 100.3 and it gave me the same error, playing around in scalebar.qml with the imports and changing them from "import Esri.ArcGISRuntime 100.3" to "import Esri.Samples 1.0
import Esri.ArcGISExtras 1.1" seemed like it fixed the issue for me.

Except now for me mapView.mapScale returns as undefined/NaN but that might just be my set up.

0 Kudos
WayneGuidry
New Contributor III

Thanks Troy for testing it.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

The issue is that there is a mixture of our QML and C++ APIs in your example. We have one API which is purely QML, and that is the API that AppStudio uses. You can tell if you are using the QML API because you will see "import Esri.ArcGISRuntime 100.x" in the code - this is the QML plugin we build and ship. If you instead want to use our C++ API, you can utilize the MapQuickView to expose the MapView to QML, and write your business logic in C++ and your UI in QML. The different development paradigms are highlighted in this doc - Qt SDK best practices—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

Long story short - if you create a new project and select the "ArcGIS Runtime Qt Quick QML" template, everything should work. If you prefer to use the C++ API, there will be more work involved - for starters, you will need to remove the "import Esri.ArcGISRuntime 100.x" from your ScaleBar.qml, expose the various Q_PROPERTYs that you need, etc.

0 Kudos
WayneGuidry
New Contributor III

Hi Lucas,

Thanks for that information. I had read about the three different ways you could use the API's but it didn't occur to me that the QML imports would be different between them. Good to know how to tell the difference now.

Since I'm really interested in the C++/QML mix, I'll start looking at exposing the necessary pieces I need.

Thanks

Wayne

0 Kudos
LucasDanzinger
Esri Frequent Contributor

I ported that over to C++ (see attached). I've not used this scalebar code before, so I'm not sure if it does what you want, but these changes should be an example of how you can make this code work with the C++ API.

0 Kudos
WayneGuidry
New Contributor III

Awesome, thanks for the sample! 

I had found an article you wrote which is extremely helpful as well: https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-qt/blog...