Thanks Martin, but I remove the layer from the layerSet before removing from QgsMapLayerRegistry. So, when I update the layer set in canvas, the layer doesn't exists.<br><br>Germán<br><br><br><div class="gmail_quote">El 16 de junio de 2009 6:51, Martin Dobias <span dir="ltr"><<a href="http://wonder.sk">wonder.sk</a>@<a href="http://gmail.com">gmail.com</a>></span> escribió:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2009/6/16 Germán Carrillo <<a href="mailto:carrillo.german@gmail.com">carrillo.german@gmail.com</a>>:<br>
<div><div></div><div class="h5">> Hi Martin.<br>
><br>
> I create the layers like the PyQGIS Wiki says:<br>
><br>
> ( For shapefiles) layer = QgsVectorLayer( layerPath, layerInfo.fileName(),<br>
> layerProvider )<br>
> Where layerPath is a QFileDialog result and layerProvider is "ogr".<br>
><br>
> If the layer is valid, I call a function to add it to canvas:<br>
><br>
> if layer.isValid():<br>
> self.agregarCapa( layer )<br>
><br>
> def agregarCapa( self, capa ):<br>
> QgsMapLayerRegistry.instance().addMapLayer( capa )<br>
> self.layers.insert( 0, QgsMapCanvasLayer( capa ) )<br>
> self.canvas.setLayerSet( self.layers )<br>
><br>
> I remove layers from the Legend class:<br>
> for i in self.layers:<br>
> if i.layer().getLayerID() == self.currentItem().layerId:<br>
> self.layers.remove( i )<br>
> QgsMapLayerRegistry.instance().removeMapLayer(<br>
> i.layer().getLayerID() )<br>
> self.canvas.setLayerSet( self.layers )<br>
> break<br>
><br>
> Then I remove the QTreeWidgetItem:<br>
> self.takeTopLevelItem( self.indexOfTopLevelItem( myItem ) )<br>
><br>
> Like in the QGIS legend, I have an item for the layer name and its geometry<br>
> type and a child item for its symbology.<br>
> The parent item (the layer item) has the attribute canvasLayer to reference<br>
> it and access its functions and attributes.<br>
><br>
> I'm using this connect line:<br>
> self.connect( QgsMapLayerRegistry.instance(),<br>
> SIGNAL("layerWasAdded(QgsMapLayer *)"), self.legend.addLayerToLegend )<br>
><br>
> The legend has another connect line to update the layer status:<br>
> self.connect( self, SIGNAL("itemChanged(QTreeWidgetItem *,int)"),<br>
> self.updateLayerStatus )<br>
><br>
> When all it's ok, remove layer always returns two lines like this:<br>
> Object::disconnect: Unexpected null parameter<br>
<br>
</div></div>I think I know where's the problem: you remove the map layer and then<br>
update layer set in canvas. When updating the layer set, the layers<br>
which have been removed get disconnected from the slots of map canvas.<br>
But that time your layer doesn't exist anymore and the pointer is<br>
invalid - thus the disonnect warning or a crash.<br>
<br>
So the solution should be to swap those two lines. Another way would<br>
be to connect to registry's layerWillBeDeleted signal (which is<br>
emitted in removeMapLayer() method when the layer still exists) and<br>
update the GUI and canvas. This would be a bit cleaner solution if<br>
there were more places in code where you remove a layer.<br>
<font color="#888888"><br>
Martin<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>-----------<br> |\__ <br>(:>__)(<br> |/ <br><br>Soluciones Geoinformáticas Libres <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br>
<br>