Page 1 of 1 (3 posts)

  • talks about »
  • pyqt


Last update:
Sun Mar 26 00:20:11 2017

A Django site.

QGIS Planet

QGIS2 compatibility plugin

Lately I’ve been spending time porting a bigger plugin from QGIS 2.8 to 3 while maintaining 2.8 compatibility. You can find it at and One code to rule them all. My target was to have to edit the

Updating PyQt signals that use lambda in QGIS with 2to3

Just for the sake of documenting things, when running qgis 2to3 on a plugin I encountered a tricky situation regarding signals. [crayon-58cfa3acd5d74893641920/] The original code: [crayon-58cfa3acd5da9095589774/] The generated code: [crayon-58cfa3acd5db0612226451/] so in do_load_project we get False instead of “my test

PSA: Please use new style Qt signals and slots not the old style

Don’t do this:


It’s the old way, the crappy way. It’s prone to error and typing mistakes. And who really wants to be typing strings as functions and arg names in it. Gross.

Do this:


Much nicer. Cleaner. Looks and feels like Python not some mash up between C++ and Python. The int argument is the default so it will use that. If you to pick the signal type you can use [type].

Don’t do this:

self.emit(SIGNAL("changed()", value1, value2))

Do this

class MyType(QObject):
   changed = pyqtSignal(str, int)

   def stuff(self):
       self.changed.emit(value1, value2)

pyqtSignal is a type you can use to define you signal. It will come with type checking, if you don’t want type checking just do pyqtSignal(object).

Please think of the poor kittens before using the old style in your code.

Filed under: pyqt, python, qgis Tagged: pyqt, qgis, qt

  • Page 1 of 1 ( 3 posts )
  • pyqt

Back to Top