[PyQt] Passing python objects in QDataStream with SIP api v2

Phil Thompson phil at riverbankcomputing.com
Wed Mar 10 12:52:47 GMT 2010


On Wed, 10 Mar 2010 11:58:48 +0000, Jugdish <jugdizh at gmail.com> wrote:
> How do you pass an arbitrary python object in/out of a QDataStream when
you
> have the SIP API set to version 2 for QVariants?
> 
>>>> import sip
>>>> sip.setapi('QVariant', 2)
>>>> from PyQt4 import QtCore
>>>> data = QtCore.QByteArray()
>>>> outstream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
>>>> outstream << {'foo':'bar'}
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unsupported operand type(s) for <<: 'QDataStream' and 'dict'
>>>> outstream << QtCore.QVariant({'foo':'bar'})
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: PyQt4.QtCore.QVariant represents a mapped type and cannot be
> instantiated

QDataStream.readQVariant() and QDataStream.writeQVariant()

Phil


More information about the PyQt mailing list