<div dir="ltr">Hi,<div><br><div class="gmail_quote"><div dir="ltr">Le lun. 29 oct. 2018 à 11:04, Luiz Motta <<a href="mailto:motta.luiz@gmail.com">motta.luiz@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I need get the signal when have change of layers order of legend.</div><div><br></div><div>I tried use the signal of  layerOrderChanged, but, crash QGIS.</div><div>Version: 3.4</div><div>Code <span style="white-space:pre-wrap;color:rgb(41,128,185)"><a href="https://github.com/qgis/QGIS/commit/4a4b62e" style="white-space:pre-wrap" target="_blank">4a4b62e</a></span></div><div>OS: Kubuntu 18.04</div><div><br></div><div>I used the Terminal Python:<br></div><div><br></div><div>def changeOrder():<br></div><div>    print('Change order')</div><div><br></div><div>root = QgsProject.instance().layerTreeRoot()<br></div><div><br></div><div>root.layerOrderChanged.connect(changeOrder) # Crash for normal layer <br></div><div><br></div><div>root.customLayerOrderChanged.connect(changeOrder) # None crash for normal layer <br></div><div><br></div><div>It is a Bug ?</div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Yes this is a bug. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>What is a custom layer ?</div></div></div></div></div></div></div></div></blockquote><div><br></div><div>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.</div><div>see <a href="https://docs.qgis.org/2.18/en/docs/user_manual/introduction/general_tools.html#working-with-the-legend-independent-layer-order">https://docs.qgis.org/2.18/en/docs/user_manual/introduction/general_tools.html#working-with-the-legend-independent-layer-order</a></div><div><br></div><div>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).</div><div><br></div><div>The crash occurs in QgsLayerTreeModel::index2node() at the return line:</div><div><br></div><div><div>QObject *obj = reinterpret_cast<QObject *>( index.internalPointer() );</div><div>return qobject_cast<QgsLayerTreeNode *>( obj );</div></div><div><br></div><div>I am not really sure how to fix it here, Martin... can you have a look it?</div><div><br></div><div>Denis</div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">





<p class="inbox-inbox-inbox-inbox-p1"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:10pt">Denis Rouzaud</span><br style="color:rgb(0,0,0);font-family:Times;font-size:medium"><a href="mailto:denis@opengis.ch" target="_blank" style="font-family:Times;font-size:medium"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt">denis@opengis.ch</span> </a><br style="color:rgb(0,0,0);font-family:Times;font-size:medium"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt"><a>+41 76 370 21 22</a></span></p><p class="inbox-inbox-inbox-inbox-p1"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt"><a><br></a></span></p></div></div>