Bug report #13304

Using "setShapeStyleSymbol" causes to Crash QGis

Added by Evgeniy Z about 9 years ago. Updated about 9 years ago.

Status:Closed
Priority:High
Assignee:-
Category:-
Affected QGIS version:2.10.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:21362

Description

I have created a module in which there is a need to create a New Print Composer and add to Composer some rectangles, setting them style by setShapeStyleSymbol. Everything works well and the rectangle is created with the necessary style. But when you try to close down QGIS, it does not close down, or causes crash (Project/ Exit QGIS).
I tried it in two versions 2.8.2, 2.10.1. Windows 7 64bit, Windows 10 32bit, Windows XP 32bit.

For example Python Console code:

@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *

self = qgis.utils

Mlayer = QgsVectorLayer("Polygon", u"Test_Polygon_Layer", "memory")
QgsMapLayerRegistry.instance().addMapLayer(Mlayer, True)

symbol = Mlayer.rendererV2().symbols()[0]

newco = self.iface.createNewComposer()
newcomp = newco.composition()
newcomp.setPlotStyle(QgsComposition.Preview)
cshape = QgsComposerShape(10, 10, 7, 4, newcomp)
cshape.setItemPosition(10, 10)
cshape.setShapeType(QgsComposerShape.Rectangle)
cshape.setUseSymbolV2(True)
cshape.setShapeStyleSymbol(symbol)
newcomp.addComposerShape(cshape)
print ''
@

Associated revisions

Revision 166e5bf9
Added by Nyall Dawson about 9 years ago

[composer] Make some set symbol methods clone symbol, nicer API
for PyQGIS (fix #13304)

History

#1 Updated by Nyall Dawson about 9 years ago

Try cloning the symbol. Change:

symbol = Mlayer.rendererV2().symbols()[0]

to

symbol = Mlayer.rendererV2().symbols()[0].clone()

#2 Updated by Evgeniy Z about 9 years ago

  • Status changed from Open to Closed

Yes! I guessed yesterday! Thanks.

Also available in: Atom PDF