Select to view content in your preferred language

Crash with sdk when i add elements

805
8
Jump to solution
05-31-2022 03:28 AM
VincentB38
New Contributor III

hello, 

I use esri's sdk, i try to create differente dynamic objects. For this, i use QML on QT for create the map. 

But, when i use a long time the application, it's crash when i create new element. i suppose is not a probleme with the C++ beacause when i don't display the elements, it's work...

I join my QML code with the subject. 

if you have any probleme (with my post) or any solution, i'm here !

import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14


Item
{
id: qmlMap
signal transmetreClique (var lat, var log, var changer, var zoom)
signal transmettreCliqueSuppression(var lat, var log, var zoom)
signal clavierToucheSuppr()
signal undo();
signal redo();

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

property bool changer : false
property int item;
property bool animer : false
property int tot : 1
property bool buttonvalue : false;

property var polygon_contour_obj : null;
property var polygon_buffer_obj : null;

property var polygon_contour : null;
property var polygon_buffer : null;

property var listPolyline : [];
property var listPolygonContour : [];
id : map

Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();

 


}

// add a map to the mapview
Map {
// add the ArcGISTopographic basemap to the map
id : fondmap
initBasemapStyle: Enums.BasemapStyleArcGISImagery

initialViewpoint: viewpoint

 

}
GraphicsOverlay {
id: graphicsOverlay
}

 

ViewpointCenter {
id: viewpoint

// Specify the center Point
center: Point {
x: 2.3522219
y: 48.856614
spatialReference: SpatialReference {wkid: 4326}
}
targetScale: 50000000.0
}

 

onMouseClicked: { //on MapView

 

const spatialReference = ArcGISRuntimeEnvironment.createObject("SpatialReference",{wkid: 4326});
const projectedPoint = GeometryEngine.project(mouse.mapPoint, spatialReference);


console.log(projectedPoint.x,projectedPoint.y,map.mapScale );

if (mouse.button == Qt.LeftButton && mouse.objectName != 'bouton')
{
transmetreClique( projectedPoint.y,projectedPoint.x,map.changer, map.mapScale)
}
else
{
transmettreCliqueSuppression( projectedPoint.y, projectedPoint.x, map.mapScale);
map.changer = false
}
}

Keys.onPressed: {


if( event.key === Qt.Key_Escape)
{
//console.log("ok");
map.animer=false;

animation.running=false
map.changer = false
if(map.listPolygonContour[map.item].length > 3)
{
map.listPolygonContour[map.item][2].visible =true
}
}
else if (event.key === Qt.Key_Delete && map.changer)
{
clavierToucheSuppr()
map.changer = false
}
}

 

Button {

width: 80
height: 30
x: qmlMap.width-width-10
y: 10
id : buttonUndo
font.pointSize: 16;

background: Rectangle {
id : fondUndo;
radius: 5
}
property bool buttonvalue : true;
//color:"yellow"

visible: true
text: ">"
flat : false
onPressed: {
fondUndo.opacity = .80

redo()
}
onReleased:
{
fondUndo.opacity = 1
}


}
Button {

width: 80
height: 30
x: qmlMap.width-width-20-buttonUndo.width
y: 10
id : buttonRedo
font.pointSize: 16;

background: Rectangle {
id : fondRedo;
radius: 5
}
property bool buttonvalue : true;
//color:"yellow"

visible: true
text: "<"
flat : false
onPressed: {
fondRedo.opacity = .80
undo()
}
onReleased:
{
fondRedo.opacity = 1
}


}

}

Point {
id: helper
x : 0
y : 0
spatialReference: SpatialReference {wkid: 4326}
}

PolygonBuilder {
id: polygon_contour
spatialReference: SpatialReference {wkid: 4326}
}

PolygonBuilder {
id: polygon_buffer
spatialReference: SpatialReference {wkid: 4326}
}

SimpleFillSymbol {
id: polygon_fill_symbol_buffer_contour
style: Enums.SimpleFillSymbolStyleNull
color: "yellow"

SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "red"
width: 1
antiAlias: true
}
}

SimpleFillSymbol {
id: polygon_fill_symbol_buffer
style: Enums.SimpleFillSymbolStyleNull
color: "yellow"

SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "blue"
width: 1
antiAlias: true
}
}

SimpleLineSymbol {
id: line_symbol_path
style: Enums.SimpleLineSymbolStyleSolid
color: "yellow"
width: 4
antiAlias: true
}

PictureMarkerSymbol {
id : pictureMarkerSymbolBorder
url : "../ressource/marqueur_rouge.png"
width : 60
height : 60
}

PictureMarkerSymbol {
id : pictureMarkerSymbolBuffer
url : "../ressource/marqueur_bleu.png"
width : 60
height : 60
}

PictureMarkerSymbol {
id : pictureMarkerSymbolStarter
url : "../ressource/marqueur_jaune.png"
width : 20
height : 20
}

PointBuilder {
id: ptBuilder
spatialReference: SpatialReference { wkid: 4326 }
}


function createGraphic(geometry, symbol) {
console.log("create graphic debut")

//I suppose, the line create the crash (beacause ofen the crash, the line "create graphic debut" it's display
const graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
console.log("1")
graphic.geometry = geometry;
console.log("2")
graphic.symbol = symbol;
console.log("create graphic fin")
return graphic;
}


function reset()
{

console.log("reset")
map.changer = false;
map.animer=false;
animation.running=false
}

function viderPoint (changeParcelle)
{

console.log("vider")
graphicsOverlay.graphics.clear()

if (map.polygon_buffer && map.polygon_contour)
{

map.polygon_buffer.destroy()
map.polygon_contour.destroy()
}

map.listPolygonContour = [];
map.listPolyline = []

map.polygon_contour = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
PolygonBuilder {
id: polygon_contour_1
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap)

//console.log(map.polygon_contour)

map.polygon_buffer = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
PolygonBuilder {
id: polygon_contour_2
spatialReference: SpatialReference {wkid: 4326}
}',qmlMap, "dynamicSnippet1" );

 

if (changeParcelle)
{
map.changer = false;
ptBuilder.setXY(2.3522219,48.856614);
//ptBuilder.setXY(0,0);
map.setViewpointCenterAndScale(ptBuilder.geometry, 50000000.0);
}
}

function modifPoint(lat,log)
{
console.log("modif pooint")
console.log("change : " + lat +" "+ log)
animation.running=false
map.changer = false
/*map.mapItems[map.item-1].opacity= 1
map.mapItems[map.item-1].coordinate = QtPositioning.coordinate(lat, log)*/
}

function addPointParcelle(lat, log,val)
{
console.log("debut add parcelle")
if (map.polygon_contour_obj)
{
var index = graphicsOverlay.graphics.indexOf(map.polygon_contour_obj);
if (index !== -1)
{
graphicsOverlay.graphics.removeOne(map.polygon_contour_obj)
}
}
map.polygon_contour.addPointXY(log,lat);
map.polygon_contour_obj = createGraphic(map.polygon_contour.geometry, polygon_fill_symbol_buffer_contour);
graphicsOverlay.graphics.append(map.polygon_contour_obj);


//lat = lat +projectedPoint.y
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}

}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolBorder);
graphicsOverlay.graphics.append(point_graphic);

map.listPolygonContour.push([log,lat,point_graphic])

map.tot = map.tot + 1
console.log("fin add parcelle")

}

function addPointParcelleBufferiser(lat, log)
{
console.log("debut add buffer")
if (map.polygon_buffer_obj)
{
var index = graphicsOverlay.graphics.indexOf(map.polygon_buffer_obj);
if (index !== -1)
{
graphicsOverlay.graphics.removeOne(map.polygon_buffer_obj)
}
}

map.polygon_buffer.addPointXY(log,lat);
map.polygon_buffer_obj = createGraphic(map.polygon_buffer.geometry, polygon_fill_symbol_buffer);
graphicsOverlay.graphics.append(map.polygon_buffer_obj);

//polygoneBufferiser.addCoordinate(QtPositioning.coordinate(lat,log))
//map.addMapItem(polygoneBufferiser)

var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add'+map.tot+'
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}

}',qmlMap)

var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolBuffer);
graphicsOverlay.graphics.append(point_graphic);
map.tot = map.tot + 1

console.log("fin add buffer")
}

function setCenter(lat,log)
{
console.log("cset center")
map.changer = false;
ptBuilder.setXY(lat, log);
map.setViewpointCenterAndScale(ptBuilder.geometry, 10000.0);

}

function clearParcours()
{

console.log("clear parcours")
while (map.listPolyline.length > 0)
{
var elem = map.listPolyline.pop()
graphicsOverlay.graphics.removeOne(elem)
}


}

function addLine (lat1,log1, lat2,log2)
{
console.log("add line")
//console.log("ok");
console.log ("lat1 : " + lat1 +", log 1 : "+ log1 + ", lat2 : "+lat2 + ",log 2 : " + log2);
if(map.tot > 9)
{
map.tot = 0;
}
else
{
map.tot++;
}
const line = {"paths":[[[log1,lat1],[log2,lat2]]],"spatialReference":{"wkid":4326}}
const line1 = ArcGISRuntimeEnvironment.createObject("Polyline", {"json": line });
const line_graphic = createGraphic(line1, line_symbol_path);
console.log(line_graphic)
map.listPolyline.push(line_graphic)
graphicsOverlay.graphics.append(line_graphic);
}


function faireClignoterPoint(lat,log)
{
console.log("cligbotter")
console.log(" rechercher : lat " + lat + "log " + log);
map.item = 0;
var trouver = false
while (map.listPolygonContour.length > map.item && !trouver)
{
console.log("lat " + map.listPolygonContour[map.item][0] + "log " + map.listPolygonContour[map.item][1]);
//console.log("val : "+ map.mapItems[i].coordinate.latitude + ' ' + map.mapItems[i].coordinate.longitude );
if (map.listPolygonContour[map.item][1] === lat && map.listPolygonContour[map.item ][0] === log)
{
console.log("trouver",map.listPolygonContour[map.item][2])
trouver = true;
map.changer = true;
console.log(map.listPolygonContour[map.item][2].visible )

//map.polygon_contour_obj[0].opacity = 2


animation1.target = map.listPolygonContour[map.item][2];
animation2.target = map.listPolygonContour[map.item][2];
animation3.target = map.listPolygonContour[map.item][2];
animation4.target = map.listPolygonContour[map.item][2];
//console.log("activer suite");
animation.running=false
animation.running=true
// console.log("activer fin");
}
else
{
map.changer = false;
}


map.item = map.item + 1;
}
}

function pointDebut(lat,log)
{
console.log("point debut")
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}

}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolStarter);
graphicsOverlay.graphics.append(point_graphic);
}

function afficherPointDebut(lat,log)
{
console.log("cpoint debut bis")
var marqueuradd = Qt.createQmlObject('
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.2
import QtPositioning 5.12
import QtLocation 5.12
import Esri.ArcGISRuntime 100.14
Point {
id: point_add
x: '+log+'
y: '+lat+'
spatialReference: SpatialReference {wkid: 4326}

}',qmlMap)
var point_graphic = createGraphic(marqueuradd, pictureMarkerSymbolStarter);
graphicsOverlay.graphics.append(point_graphic);
}

function subButton()
{
console.log("sub bouton")
buttonRedo.destroy();
buttonUndo.destroy();
}

SequentialAnimation{
id: animation
running: false
loops: Animation.Infinite
PropertyAnimation {
id: animation1
//target: rect
to:0
properties: "visible"
duration: 100
}
PropertyAnimation {
id: animation2
//target: rect
to:0
properties: "visible"
duration: 300
}
PropertyAnimation {
id: animation3
//target: rect
to:1
properties: "visible"
duration: 100
}
PropertyAnimation {
id: animation4
//target: rect
to:1
properties: "visible"
duration: 300
}
}
}

0 Kudos
1 Solution

Accepted Solutions
AndrewBladon
Esri Contributor

Hi @VincentB38,

Thank you for providing the additional information. We understand that you have a Qt Widgets application and have embedded a QML file that uses the Runtime Qt API for QML in your application using the QQuickWidget class.

Common programming patterns used with the Runtime Qt API are summarised in the Map and Scene View Options table. As shown, for Qt Widgets applications we typically use widgets classes in our C++ API (e.g. MapGraphicsView). Using the C++ API allows the business logic for an application to be written with C++. The C++ API can also be combined with a Qt Quick interface (e.g. MapQuickView), enabling QML components to be used with C++ business logic. The QML API is commonly used with Qt Quick based apps.

Is there a reason that you have chosen to use the QML API with your Qt Widgets application? Are you able to consider trying one of the more common patterns instead?

View solution in original post

0 Kudos
8 Replies
GuillaumeBelz
Esri Contributor

Bonjour

Il y a eu un problème lors de la publication de votre code, tout a été traduit en français. Pouvez-vous reposter votre code ?

Merci

Guillaume

0 Kudos
VincentB38
New Contributor III

I'm sorry, i fixe it !

0 Kudos
AndrewBladon
Esri Contributor

Hi @VincentB38.

Thanks for sharing your code. Unfortunately we have been unable to reproduce the issue. Could you provide us with more information, for example:

  • Instructions outlining how we can reproduce the issue.
  • A small code snippet that we can use to reproduce the crash.

Thanks.

0 Kudos
VincentB38
New Contributor III

Hi @AndrewBladon ,

I can't share more code because it's a complete application and i don’t share more. But, i can try to add informations

For create the bug, i use ESRI on three QQuickWidget, on diffierent tab on tabWidget. I realize many action on tab. I change and i try to realize other action (like add point, sub point, delete every point "vider()" etc .) so, after i realize this, my application crash...

I realise different tests with the esri plugin (the version on QT without the sdk) and, i don't have any problem. I change for the sdk esri and, my application crash... Today, i'm not really sure, but is most possible it's esri sdk. I mean it's overflow...

I realize other test, and, after, i can suppose, the crash is in link with the polygone creation or display.

0 Kudos
AndrewBladon
Esri Contributor

Hi @VincentB38,

Thank you for providing the additional information. We understand that you have a Qt Widgets application and have embedded a QML file that uses the Runtime Qt API for QML in your application using the QQuickWidget class.

Common programming patterns used with the Runtime Qt API are summarised in the Map and Scene View Options table. As shown, for Qt Widgets applications we typically use widgets classes in our C++ API (e.g. MapGraphicsView). Using the C++ API allows the business logic for an application to be written with C++. The C++ API can also be combined with a Qt Quick interface (e.g. MapQuickView), enabling QML components to be used with C++ business logic. The QML API is commonly used with Qt Quick based apps.

Is there a reason that you have chosen to use the QML API with your Qt Widgets application? Are you able to consider trying one of the more common patterns instead?

0 Kudos
VincentB38
New Contributor III

Hi @AndrewBladon 

Thank's for you answer. I try to realise this solution. I used QML because differents tutorials recomand to use this (ofen i use ESRI SDK)

 

After many developpement houres, i change my solution, i use Layout for add dynamicly QWidget. After this, i use the same functions but with the C++ SDK. Now , It’s Time to fix the bug but and other probleme.

But i have a little probleme with my development. indeed, i would like animate the point whene the user select this (in the QML i’ve done this) but, i don't know how to do for realising this...  It's verry importante for users...

 

Thank's for your answer ! I can move !

0 Kudos
AndrewBladon
Esri Contributor

Hi @VincentB38,

From your message I understand that you have managed to find a way to resolve the crash that you reported. We are pleased to hear this.

I also understand that you are trying to use the C++ API to highlight a point that is selected by the user. This can be done by:

  1. Performing a GeoView::identifyLayers operation to find features near to the point clicked by the user.
  2. Using the FeatureLayer::selectFeatures method to select these features.

An example of this can be seen in the C++ Feature layer selection sample, which can be accessed via the qt samples repository or using the Qt C++ Sample Viewer Application.

I hope this helps you with the next stage of your work!

 

0 Kudos
VincentB38
New Contributor III

hi @AndrewBladon 
Thank you for your help. After reasearch, i create an animation with QTimer and i set visibility's object for create animation. 

It's work ! I could change QML with c++.  

0 Kudos