[PyKDE] PyQt4's QVariant returns tuples?
Phil Thompson
phil at riverbankcomputing.co.uk
Tue Dec 27 19:27:11 GMT 2005
On Tuesday 27 December 2005 7:01 pm, Andreas Pakulat wrote:
> Hi,
>
> does somebody know why QVariant.to* returns tuples when asking for
> simple datatypes, like int and double?
>
> AFAICS it returns the value and wether the conversion was successful, is
> this intended behaviour? Documented somewhere? Should I always use
>
> variant.toInt()[0] to get to the int?
>
> To me it seems a bit inconsistent, some of the to* functions return only
> the data, some return a tuple and it's definitely not like Qt itself
> handles the to* functions.
If a C++ function returns multiple values (the return value and via a pointer
in this case) then they are returned as a tuple. It's always been like this
and is consistent. A more natural idiom to use is...
value, ok = variant.toInt()
Phil
More information about the PyQt
mailing list