IdentifyLayerCompleted signal is getting called increasingly

506
4
Jump to solution
08-22-2017 02:08 AM
MarcWouters
New Contributor III

I connect the IdentifyLayerCompleted signal with a slot, in which I check the TaskWatcher's taskId() to make sure I have the correct signal.

However, every time I execute the identifyLayer method, the number of time this slot is called increases, using the same taskID for each call.

How can I remove this extra signal calls ?

void Myclass::mouseClickedSlot(QMouseEvent& mouseEvent)
{
   connect(_mapView, &MapQuickView::identifyLayerCompleted, this, &Myclass::clickedSlot);
   for (int i = 0; i < _map->operationalLayers()->rowCount(); ++i) {
      FeatureLayer* thisLayer = (FeatureLayer*)(_map->operationalLayers()->at(i));
      TaskWatcher tw = _mapView->identifyLayer(thisLayer, mouseEvent.x(), mouseEvent.y(), 10, false, 10);
      _identifyTasks.push_back(tw.taskId());
   }
}

void Myclass::clickedSlot(QUuid taskID, IdentifyLayerResult* identifyResult)
{
    if (find(_identifyTasks.begin(), _identifyTasks.end(), taskID) == _selectedTasks.end()) {
      // not the taskID I was expecting
       return;
   }
   // do something, depending on the layer   
   // ...
}

0 Kudos
1 Solution

Accepted Solutions
LukeSmallwood
Esri Contributor

Hi Marc,

I think this line is the problem:

connect(_mapView, &MapQuickView::identifyLayerCompleted, this, &Myclass::clickedSlot);

It looks like this is being called every time you receive the QMouseEvent form your mouseClickedSlot - that means you will be getting a new connection each time. If possible you should move the connection to the c'tor of the class (or immediately after the MapQuickView is created - possibly in the component completed method?) so that this only happens once. I think you may also want to clear the _identifyTasks container each time you enter the mouseClickedSlot or this will continue to grow?

I hope that helps,

Luke

View solution in original post

4 Replies
LukeSmallwood
Esri Contributor

Hi Marc,

I think this line is the problem:

connect(_mapView, &MapQuickView::identifyLayerCompleted, this, &Myclass::clickedSlot);

It looks like this is being called every time you receive the QMouseEvent form your mouseClickedSlot - that means you will be getting a new connection each time. If possible you should move the connection to the c'tor of the class (or immediately after the MapQuickView is created - possibly in the component completed method?) so that this only happens once. I think you may also want to clear the _identifyTasks container each time you enter the mouseClickedSlot or this will continue to grow?

I hope that helps,

Luke

MarcWouters
New Contributor III

Hi Luke,

What a fast response time !

You are right about creating a new connection every time I click the mouse.

But then I have a related question : selectFeatures() works on layers, queryFeatures() works on tables.
Should I also make these connections in the constructor for all the layers and tables I use (which can vary during the lifetime of the application), or is it possible to disconnect every time the slot has done it's work ?

Marc

0 Kudos
LukeSmallwood
Esri Contributor

Hi Marc, if you know that you want to use the connection just once it would be a good idea to disconnect it afterwards. A simple way to do this is to store the return type of the original connection and then pass this to a call to disconnect (QObject Class | Qt Core 5.9 ) once the work is done.

It is still good practice to make sure that you are not creating multiple copies of the same connection so I would recommend moving those calls to a place where they will only be executed once - e.g. where the layers are first set up. 

MarcWouters
New Contributor III

Thanks Luke,

I wish all my programming problems could be fixed so quickly

Regards,

Marc

0 Kudos