[PyQt] Extracting QMap<int, QVariant> from a QDataStream

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jul 12 16:30:22 BST 2007


On Thursday 12 July 2007 4:20 pm, you wrote:
> On 7/12/2007 4:55 PM, Phil Thompson wrote:
> >> I'm trying to receive drops on my widget from a QListWidget. As the Qt4
> >> documentation is fairly bad regarding what data is stored in the
> >> QMimeType of a QDropEvent, I've been looking at the source. The data is
> >> packed into a QDataStream with the following:
> >>
> >> int r, c;
> >> QMap<int, QVariant> v;
> >> stream >> r >> c >> v;
> >>
> >> Where r and c are row and column respectively (extracting with a
> >> readUInt32 from my drop event confirms that). I think the QMap maps
> >> column to text. How do I extract that QMap from the data stream? I
> >> imagine it's not going to be straightforward as QMap isn't present in
> >> the bindings.
> >
> > Yuck. I can't see how to do this generically. It might need a special
> > utility function - unless anybody has a bright idea?
>
> What is the problem, exactly? Exposing the QMap template to Python?

No, the problem is not being able to introspect the data to work out how to 
convert it. So you have to have a dedicated convertor function that you know 
to call in a particular situation.

Phil


More information about the PyQt mailing list