[QGIS-Developer] Converting plugins to QGIS 3
matthias at opengis.ch
Wed May 10 22:59:28 PDT 2017
On 5/10/17 8:03 PM, C Hamilton wrote:
> I am wondering how important it is to import the modules separately.
> Such as:
> from qgis.core import QGis, QgsCoordinateTransform, QgsRectangle,
> QgsPoint, QgsGeometry
> Does it really make a difference? I am finding that you have to make
> sure every part of your code is exercised so that nothing was missed.
> By doing the above there is more of a chance to have a bug. Perhaps
> for PyQt4.QtGui it makes sense, but there is less chance to have a
> python error if you keep.
It doesn't make a difference for QGIS 3 itself. If you write new code
from scratch using wildcard imports on PyQt5, it will just work the way
it has worked in QGIS 2.
The point is, that some classes have been moved between modules from
PyQt4 to PyQt5 (e.g. all widgets from QtGui to QtWidgets).
The migration tool 2to3 can help with this - but only if the imports are
There are other ways to upgrade your code than 2to3, the advantage of
the proposed approach is that it makes your code closer to "best
practice" - but it's up to you to decide.
> from qgis.core import *
> from PyQt4.QtGui import *
> from qgis.gui import *
More information about the QGIS-Developer