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.

The original code:

The generated code:

so in do_load_project we get False instead of “my test argument”, why?
well due to a subtle difference in the generated code. in the original code we had the signature triggered() which has no arguments, so in our lambda extra_arg gets passed my_arg.
in the generated code, triggered actually has an optional param checked [1] which if emitted gets passed to extra_arg causing the problem.

The correct code (note the additional argument in the lambda definition)

some reference:
[0] http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html
[1] http://doc.qt.io/qt-4.8/qaction.html#triggered

Posted in PyQt, QGIS Plugins

Leave a Reply

Mythenstrasse 37A
8840 Einsiedeln

Email: info@opengis.ch
Twitter: @OPENGISch
Mobile: +41 (0)79 467 24 70
Skype: mbernasocchi
Support QField development
%d bloggers like this: