[PyQt] qvariant and python objects
phil at riverbankcomputing.com
Mon Jun 23 08:50:10 BST 2008
On Sun, 22 Jun 2008 15:21:07 -0700, "Adam Tenderholt"
<atenderholt at gmail.com> wrote:
> I've created a QVariant object by passing a Python object
> (specifically, a list of numpy arrays) to its constructor, and I'm
> trying to have it read into a QDataStream object. Unfortunately, it
> doesn't work and gives me the error 'QVariant::save: unable to save
> type 428.'. The relevant code is below:
> mimeData = QtCore.QMimeData()
> encodedData = QtCore.QByteArray()
> stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly)
> temp = QtCore.QVariant(element.coords)
> stream << temp
> As near as I can tell (printing debug messages immediately before and
> after), it has trouble with the 'stream << temp' line. Should I be
> doing something else, or can I not use QVariants in this way?
> This is with Python 2.5.1 on a Mac running OS X 10.5.3 with Qt 4.4.0,
> sip 4.76, and PyQt 4.4.2.
While QVariant knows how to copy an arbitrary Python object (which is just
reference count manipulation) it doesn't know how to serialise one.
More information about the PyQt