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

Jugdish jugdizh at gmail.com
Wed Mar 10 13:22:22 GMT 2010


Aha! Thanks

On Wed, Mar 10, 2010 at 12:52 PM, Phil Thompson <phil at riverbankcomputing.com
> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100310/9bf1db85/attachment.html>


More information about the PyQt mailing list