Im loading a shapefile using the method
QgsVectorLayer() and adding a style to it using the method
loadSldStyle() and the path to the sld file. So far so good.
What I want now is to export that style as .qml file. I suppose that maybe I could use the method
exportNamedStyle() but this method use an argument of type
QDomDocument. I have no idea how to create this this object.
Can anyone tell me how to export the .qml file of this loaded layer using python?
Using the method saveNamedStyle() it only works if I use the python console inside qgis. In the python console in the qgis desktop I did this:
vlayer = iface.addVectorLayer("/home/inesf/sag/prodgen/SAGautodataset/Cystoseira_compressa.shp", 'mylayer', 'ogr') vlayer.loadSldStyle("/home/inesf/sag/prodgen/SAGautodataset/Cystoseira_compressa.sld") vlayer.saveNamedStyle("/home/inesf/sag/prodgen/SAGautodataset/Cystoseira_compressa.qml")
And it worked fine, it exported a .qml file with the same style defined in the SLD file. Perfect.
When I do this in the python console outside the QGIS desktop, it exports a .qml file but empty.
When I run a python program with this code with the same code, does not give errors, but nothing happens.