I'm having some compatibility problems with PyQt5, as expected some of the scripts I wrote are not working.
My biggest issues are with these two PyQt4 functions:
layer.pendingFields()
layer = QgsMapLayerRegistry.instance().mapLayersByName('Layer_Name')[0]
Is there a comparable function in PyQt5?
Does it work like the old functions?
In general it would be great to have something like a dictionary, where you could look for the old function and see the relate translation or substitutes in PyQt5.
Answer
I'm assuming when you say "PyQt5", you mean you are using QGIS 3.x. In which case:
layer.pendingFields()
becomes:
layer.fields()
And:
layer = QgsMapLayerRegistry.instance().mapLayersByName('Layer_Name')[0]
becomes:
layer = QgsProject.instance().mapLayersByName('Layer_Name')[0]
You can read here about the API changes and here for the PyQt4 and PyQt5 differences.
No comments:
Post a Comment