Hi Martin.<br><br>I create the layers like the PyQGIS Wiki says: <br><br>( For shapefiles) layer = QgsVectorLayer( layerPath, layerInfo.fileName(), 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( 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 type and a child item for its symbology.<br>
The parent item (the layer item) has the attribute canvasLayer to reference it and access its functions and attributes.<br><br>I'm using this connect line: <br>self.connect( QgsMapLayerRegistry.instance(), 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)"), self.updateLayerStatus )<br><br>When all it's ok, remove layer always returns two lines like this: Object::disconnect: Unexpected null parameter<br>
<br><br>Thanks by your help.<br><br>Germán.<br><br><div class="gmail_quote">El 14 de junio de 2009 5:22, 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/11 Germán Carrillo <<a href="mailto:carrillo.german@gmail.com">carrillo.german@gmail.com</a>>:<br>
<div class="im">> Hi.<br>
><br>
> I'm using PyQGIS. I have three classes in my app: Viewer, Legend and Load.<br>
> The Viewer class is the main one, the Load class add some data to canvas.<br>
> The Legend class has a SLOT to capture the layerWasAdded SIGNAL from the<br>
> QgsMapLayerRegistry class and when it happens add an item in a QTreeWidget.<br>
><br>
> The Legend class can remove layers. So, I have a problem with the SIGNAL<br>
> layerWasAdded. When I remove a layer I get multiple lines like this:<br>
><br>
> Object::disconnect: Unexpected null parameter<br>
><br>
> After that, if I add the same layer again I get a segmentation fault that<br>
> crashes my app.<br>
><br>
> This happen even if I use a custom SIGNAL passing the layer object as<br>
> parameter from my Load class.<br>
<br>
</div>Hi German,<br>
<br>
some code from your app would be helpful. How do you create instances<br>
of the layer classes? How do you delete the layers?<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>