QML disable 'triggered.connect()'

2061
2
08-09-2018 08:24 AM
Adri2cPérez_Beneito
Occasional Contributor

Hi all,

I have a QML app where I add features every 5 seconds getting the GPS point coordinates using 'LocationDisplay QML Type'. I cannot disconnect the trigger (related with 'Timer' object) once connected.. I created a 'Timer' object in order to loop this feature creation. I want to call the disconnect when => 'locationDisplay.stop()'. Whether with a button I call the 'addFunctionality("stopMode")' function, the trigger is still running..

Any suggestions?

Timer {
             id: timer
             interval: 5000;
             repeat: true;
             running: true;
        }
        function addFunctionality(arg) {
            if(arg === "compassMode"){
              mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeCompassNavigation;
              mapView.locationDisplay.start();
            }else if(arg === "navigationMode"){
                mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeNavigation;
                mapView.locationDisplay.start();
                var featureAttributes = {"XXXX" : "XXXX"};
                timer.start();
                timer.triggered.connect(function () {
                      mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
                      var point = mapView.locationDisplay.mapLocation;
                      var feature = featureTable.createFeatureWithAttributes(featureAttributes, point);
                      featureTable.addFeature(feature);
                 })
            }else{
                mapView.locationDisplay.stop();
            }
         }

Best

A.

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

You have a few options. The reason it is still adding is because the timer is still emitting the triggered signal, and that signal has been connection to an inline function (and never disconnected). Some things to try:

1) When you call stop() on the LocationDisplay, stop the timer. 

2) Instead of connecting in-line to the function, split the function out, and then call disconnect when you want.

function writeToTable() {
    mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
    var point = mapView.locationDisplay.mapLocation;
    ...
}

                
if(arg === "compassMode"){
    mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeCompassNavigation;
    mapView.locationDisplay.start();
} else if(arg === "navigationMode"){
    mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeNavigation;
    mapView.locationDisplay.start();
    var featureAttributes = {"XXXX" : "XXXX"};
    timer.start();
    timer.triggered.connect(writeToTable);
} else {
    mapView.locationDisplay.stop();
    timer.triggered.disconnect(writeToTable);
}

3) Use QML Connections to declaratively connect to the Timer's signal - Connections QML Type | Qt QML 5.11 . You could make use of the enabled property here so the connection is only enabled if certain conditions are true, such as if arg is "navigationMode"

Adri2cPérez_Beneito
Occasional Contributor

Thanks!!!  Make sense..

Cheers

0 Kudos