[QGIS-Developer] Crash for signal layerOrderChanged

Denis Rouzaud denis.rouzaud at gmail.com
Mon Oct 29 08:35:46 PDT 2018


Hi,

Le lun. 29 oct. 2018 à 11:04, Luiz Motta <motta.luiz at gmail.com> a écrit :

> Hi,
>
> I need get the signal when have change of layers order of legend.
>
> I tried use the signal of  layerOrderChanged, but, crash QGIS.
> Version: 3.4
> Code 4a4b62e <https://github.com/qgis/QGIS/commit/4a4b62e>
> OS: Kubuntu 18.04
>
> I used the Terminal Python:
>
> def changeOrder():
>     print('Change order')
>
> root = QgsProject.instance().layerTreeRoot()
>
> root.layerOrderChanged.connect(changeOrder) # Crash for normal layer
>
> root.customLayerOrderChanged.connect(changeOrder) # None crash for normal
> layer
>
> It is a Bug ?
>

Yes this is a bug.

>
> What is a custom layer ?
>

It's not the layer that is custom, it's the order. That's the way to have a
layer order that is differement from the one in the legend.
see
https://docs.qgis.org/2.18/en/docs/user_manual/introduction/general_tools.html#working-with-the-legend-independent-layer-order

For technical details, it seems that the signal is emitted
before QgsLayerTreeModel::removeRows could return true. And a new repaint
of the layer tree is requested (while still in removing rows).

The crash occurs in QgsLayerTreeModel::index2node() at the return line:

QObject *obj = reinterpret_cast<QObject *>( index.internalPointer() );
return qobject_cast<QgsLayerTreeNode *>( obj );

I am not really sure how to fix it here, Martin... can you have a look it?

Denis




-- 

Denis Rouzaud
denis at opengis.ch  <denis at opengis.ch>
+41 76 370 21 22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20181029/65830b2d/attachment.html>


More information about the QGIS-Developer mailing list