[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] Pickle QFlags ?
From: Kernc <kerncece () gmail ! com>
Date: 2015-11-14 22:52:48
Message-ID: CAFh6oAzJS4e-CYtqRNi1hEmKTAkJ-Ek20u4w3=LgtSK0ddxWRA () mail ! gmail ! com
[Download RAW message or body]
Hi,
The PyQt docs mention that the enums from Qt namespace are pickleable
[1], which is thankfully indeed the case.
>>> from PyQt5.QtCore import Qt
>>> type(pickle.loads(pickle.dumps(Qt.LeftButton))) # works
PyQt5.QtCore.Qt.MouseButton
What doesn't work, however, but isn't exactly obvious that it
shouldn't, is pickling QFlags, combinations of enum values, e.g.
>>> pickle.dumps(Qt.LeftButton | Qt.RightButton)
PicklingError: Can't pickle <class 'PyQt5.QtCore.MouseButtons'>:
attribute lookup MouseButtons on PyQt5.QtCore failed
QFlags, while a full-blown C++ class, still represents just a single
integer state, which should be trivial to store/restore.
With PicklingError being about "attribute lookup MouseButtons on
PyQt5.QtCore failed," and since MouseButton is in
PyQt5.QtCore.*Qt*.MouseButton, is this perhaps a bug?
Could I possibly make it work now, or could it possibly be fixed in a
few lines in sip code to make QFlags picklable?
Thanks.
[1]: http://pyqt.sourceforge.net/Docs/PyQt5/pickle.html
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic