[PyQt] returning numpy numbers in QVariant
jeremy at jeremysanders.net
Fri Apr 23 14:08:39 BST 2010
Phil Thompson wrote:
> Are numpy numbers regular ints/floats or are they a sub-class specific to
> QVariant has been changed (over time) to make sure that no information is
> lost when converting from and to the original object. So an int sub-class
> will stay as a Python object and will not get converted to a C++ int.
> If this is the problem then the fix is to explicitly convert the numpy
> number to a base Python type before converting to a QVariant...
> return QVariant(float(a))
> ...and this will work for older versions as well.
That workaround works well - thanks.
numpy numbers have their own type (there are actually several types as you
can choose the precision), so that's probably what causes the QVariant
In : import numpy
In : a = numpy.array([1.])
In : type(a)
Out: <type 'numpy.float64'>
More information about the PyQt