Bug report #14390

Updated by Giovanni Manghi about 7 years ago

In http://qgis.org/api/qgsmaplayer_8cpp_source.html#l00076 you can see the ID of a layer is generated by appending the current date to the layer name (with some minor verification applied). If several layers with the same name are created simultaneously, QGIS will assign them the same ID.

If they are later added to the map layer registry, only the last layer added to it will actually be in it, and will overwrite the previously 'stored' layer with that same ID.

I found this out while attempting to add similarly named layers to groups: checks failed when comparing the provided layer by it's id with the one stored in the map layer registry. The post (and what I found out, as the solution) is here:

http://gis.stackexchange.com/questions/180987/qgis-2-10-adding-layers-to-legend-groups-programatically-fails-ocassionally-wi/182424#182424



The solution I propose is to append an UUID in the ID instead of the date, to avoid this issue.

Back