[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QDataStream and template classes
From:       ekhumoro <ekhumoro () gmx ! com>
Date:       2016-12-10 20:35:10
Message-ID: 60bc467c-1f36-4d96-ee16-481b4325a2fb () gmx ! com
[Download RAW message or body]

On 26/11/16 18:09, Phil Thompson wrote:
> On 26 Nov 2016, at 5:38 pm, ekhumoro <ekhumoro@gmx.com> wrote:
>>
>> If I have received a file serialized by QDatastream that uses
>> template classes such as QList<double> and QVector<QPoint>, am I
>> right in saying there is no way to read it using PyQt?
>>
>> I see there is readQVariantList which can read QList<QVariant>, but
>> there does not seem any general way to handle template classes. I
>> suppose it's not surprising that PyQt can't do this, but I just
>> wanted to confirm there are no work-arounds.
>
> I can't think of any.
>
> Phil

Well, it seems there is a way to do this using the existing methods. It 
just requires some knowledge of the datastream format:

     http://doc.qt.io/qt-4.8/datastreamformat.html

Fortunately it is quite simple, so a QVector<QPoint> can be read like this:

     points = []
     length = stream.readUInt32()
     for index in range(length):
         point = QPoint()
         stream >> point
         points.append(point)
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic