Skip to main content
edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
Tweeted twitter.com/StackGIS/status/883517253383319558

I have a stand-alone pyqgis application that can display vector data. I have implemented a routine that setsets layer's renderer as below:

def set_sym(layer):
    symbol = QgsMarkerSymbolV2.createSimple({})
    symbol_layer = QgsSimpleMarkerSymbolLayerV2()
    symbol_layer.setColor(QColor(0, 0, 0, 255))
    symbol_layer.setName('circle')
    symbol_layer.setSize(1.0)
    symbol.appendSymbolLayer(symbol_layer)
    renderer = QgsSingleSymbolRendererV2(symbol)
    layer.setRendererV2(renderer)

It works. However, if I call it a second time on a layer, then immediately go to exit the program, then it hangs, & I have to kill the background python process to get out of it. I've already checked that the newly created renderer and the layer.rendererV2() are different and their symbol() are also different (I mean the memory addresses are different). So, it makes me think that the setRendererV2() routine is not replacing the renderer cleanly, hence hanging the program upon quitting right after the second call on the same layer. Please let me know if there is something I missed that caused this.

I have a stand-alone pyqgis application that can display vector data. I have implemented a routine that set layer's renderer as below:

def set_sym(layer):
    symbol = QgsMarkerSymbolV2.createSimple({})
    symbol_layer = QgsSimpleMarkerSymbolLayerV2()
    symbol_layer.setColor(QColor(0, 0, 0, 255))
    symbol_layer.setName('circle')
    symbol_layer.setSize(1.0)
    symbol.appendSymbolLayer(symbol_layer)
    renderer = QgsSingleSymbolRendererV2(symbol)
    layer.setRendererV2(renderer)

It works. However, if I call it a second time on a layer, then immediately go to exit the program, then it hangs, I have to kill the background python process to get out of it. I've already checked that the newly created renderer and the layer.rendererV2() are different and their symbol() are also different (I mean the memory addresses are different). So, it makes me think that the setRendererV2() routine is not replacing the renderer cleanly, hence hanging the program upon quitting right after the second call on the same layer. Please let me know if there is something I missed that caused this.

I have a stand-alone pyqgis application that can display vector data. I have implemented a routine that sets layer's renderer as below:

def set_sym(layer):
    symbol = QgsMarkerSymbolV2.createSimple({})
    symbol_layer = QgsSimpleMarkerSymbolLayerV2()
    symbol_layer.setColor(QColor(0, 0, 0, 255))
    symbol_layer.setName('circle')
    symbol_layer.setSize(1.0)
    symbol.appendSymbolLayer(symbol_layer)
    renderer = QgsSingleSymbolRendererV2(symbol)
    layer.setRendererV2(renderer)

It works. However, if I call it a second time on a layer, then immediately go to exit the program, it hangs & I have to kill the background python process to get out of it. I've already checked that the newly created renderer and the layer.rendererV2() are different and their symbol() are also different (I mean the memory addresses are different). So, it makes me think that the setRendererV2() routine is not replacing the renderer cleanly, hence hanging the program upon quitting right after the second call on the same layer. Please let me know if there is something I missed that caused this.

Source Link
For Comment
  • 1.1k
  • 7
  • 23

QgsVectorLayer setRenderer problem with lingering reference to old renderer

I have a stand-alone pyqgis application that can display vector data. I have implemented a routine that set layer's renderer as below:

def set_sym(layer):
    symbol = QgsMarkerSymbolV2.createSimple({})
    symbol_layer = QgsSimpleMarkerSymbolLayerV2()
    symbol_layer.setColor(QColor(0, 0, 0, 255))
    symbol_layer.setName('circle')
    symbol_layer.setSize(1.0)
    symbol.appendSymbolLayer(symbol_layer)
    renderer = QgsSingleSymbolRendererV2(symbol)
    layer.setRendererV2(renderer)

It works. However, if I call it a second time on a layer, then immediately go to exit the program, then it hangs, I have to kill the background python process to get out of it. I've already checked that the newly created renderer and the layer.rendererV2() are different and their symbol() are also different (I mean the memory addresses are different). So, it makes me think that the setRendererV2() routine is not replacing the renderer cleanly, hence hanging the program upon quitting right after the second call on the same layer. Please let me know if there is something I missed that caused this.