Bug report #17307

Problem with conversion of python strings, e.g. when labeling using setCustomProperty()

Added by Markus Woehling almost 4 years ago. Updated over 2 years ago.

Category:Python bindings / sipify
Affected QGIS version:2.18.13 Regression?:Yes
Operating System:Windows 10 x64 Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:25205


For me it's not possible anymore to configure labeling (for QgsVectorLayer) using setCustomProperty().

I found out that setCustomProperty() is working fine in the python console.
So my problem is not setCustomProperty() itself, but something with the QVariant and/or QLatin1String type.

Labeling seems to be correctly configured when I check it in the python console:

layer = iface.activeLayer()




But when I look at the types the result is this:


<class 'future.types.newstr.newstr'>


<class 'future.types.newstr.newstr'>

This code does NOT make labeling work:

layer.setCustomProperty("labeling", layer.customProperty("labeling"))
layer.setCustomProperty("labeling/enabled", layer.customProperty("labeling/enabled"))

But this code does:

layer.setCustomProperty("labeling", 'pal')
layer.setCustomProperty("labeling/enabled", 'true')

And this code also - at least in the python console:


I am not able to workaround this issue, because in my plugin the str() function always return a "newstr".
Do you have any hints how I could workaround this issue?

Maybe this line of code is the cause of this problem (QgsVectorLayer.cs, line 4546 in master):

if ( customProperty( QStringLiteral( "labeling" ) ).toString()==QLatin1String( "pal" ) )


#1 Updated by Giovanni Manghi almost 4 years ago

  • Priority changed from Normal to High

#2 Updated by Borys Jurgiel over 3 years ago

  • Category changed from Python plugins to Python bindings / sipify

#3 Updated by Jürgen Fischer over 2 years ago

  • Status changed from Open to Feedback

Please test with QGIS 3.4 - QGIS 2.18 reached it's end of life.

#4 Updated by Markus Woehling over 2 years ago

With QGIS 3.4 everything is working fine.

#5 Updated by Nyall Dawson over 2 years ago

  • Resolution set to fixed/implemented
  • Status changed from Feedback to Closed

Also available in: Atom PDF