[PyQt] Exceeding max C/C++ int value in signal causes value corruption - most elegant workaround?
Damon Lynch
damonlynch at gmail.com
Fri Jun 5 22:17:19 BST 2015
Hello,
Using PyQt 5.4.1 and python 3.4.3 on an amd64 Ubuntu 15,04, I have run
into a bug in my code
<http://bazaar.launchpad.net/%7Edlynch3/rapid/zeromq_pyqt/view/head:/rapid/rapid.py#L125>
where an int value being sent out in a signal is being erroneously
received as a negative value when it is greater than the maximum int
value in C/C++
<http://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3>
on the same platform.
For instance, the max int value in C/C++ on my machine is 2147483647.
When my python code emits a signal with an int value less than that,
it's received fine. More than that, and the received value is wrong,
e.g. emit 2153451441 and it is received as -2141515855.
Needless to say when writing my code I had never considered the
possibility of this bug because in python 3 there is no maximum integer
size.
What is the most pythonic, elegant and efficient way to work around this
problem? Off the top of my head I could convert the int to bytes, and
convert it back again once received, but perhaps there is a better way
to emit the signal? The docs
<http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html> say 'If an
argument doesn’t have a corresponding C++ type then it is wrapped in a
special C++ type that allows it to be passed around Qt’s meta-type
system while ensuring that its reference count is properly maintained.'
Should I instead simply bundle the signal's values into a Python class
and emit that?
Thanks!
Damon
--
http://www.damonlynch.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150606/ff23b0f1/attachment.html>
More information about the PyQt
mailing list