I used the following code to label the line features(roads) in a layer.It works in the console, but not by python code(application) It works for the points too.
What did I do wrong?
def labell(self):
layer = self.iface.mapCanvas().currentLayer()
palyrr = QgsPalLayerSettings()
palyrr.readFromLayer(layer)
palyrr.enabled = True
palyrr.fieldName = 'name'
palyrr.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'08','')
palyrr.writeToLayer(layer)
layer.commitChanges()
self.iface.mapCanvas().refresh()