Reputation: 300
in the "Differences Between PyQt4 and PyQt5" section (http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html), I can read the following line:
Unlike PyQt4, PyQt5 supports the definition of properties, signals and slots in classes not sub-classed from QObject (i.e. in mixins).
However, in the "Support for Signals and Slots" section (http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html), I can read:
New signals should only be defined in sub-classes of QObject. They must be part of the class definition and cannot be dynamically added as class attributes after the class has been defined.
Am I misunderstanding something or the 2 sentences contradict each other?
Upvotes: 1
Views: 971
Reputation: 11969
Note the in mixins part. It means you can do something like:
from PyQt5.QtCore import pyqtSignal, QObject
class SignalMixin:
sig = pyqtSignal()
class Obj(SignalMixin, QObject):
pass
o = Obj()
o.sig.connect(lambda: print('foo'))
o.sig.emit()
Upvotes: 2