[PyQt] Method overloading with nested lists in PyQt5
Phil Thompson
phil at riverbankcomputing.com
Fri May 13 15:55:03 BST 2016
On 13 May 2016, at 3:05 pm, Matthias Kuhn <matthias at opengis.ch> wrote:
>
> Hi,
>
> While updating to PyQt5 (and python3) I am experiencing an issue with overloaded methods where one overload takes a list of items and another overload takes a list of a list of items.
>
> When called with a list of a list of items, a TypeError is produced warning that "index 0 has type 'list' but 'item' is expected.
>
> It seems that the first overload for a "list of something" is found and when "something" doesn't match, no different list overloads are tried which might still be of type "list of something else".
>
> This works fine with PyQt4. Does this ring a bell for someone?
>
> Here a short (handwritten) example of the situation.
>
> Regards
> Matthias
>
>
> ----------------------------------
>
> class Point
> {
> double x;
> double y;
> };
>
> typedef QVector<Point> Line;
> typedef QVector<Line> Polygon; // Can contain multiple rings for holes
>
> class Geometry
> {
> static bool compare(const Point&, const Point&); // Point
> static bool compare(const Line&, const Line&); // QVector<Point>
> static bool compare(const Polygon&, const Polygon&); // QVector<QVector<Point> >
> }
>
> >> Geometry.compare( [[Point(1,1), Point(2,2,)]], [[Point(1,1), Point(2,2)]] )
> TypeError: index 0 has type 'list' but 'Point' is expected
PyQt5 only checks the type of the collection. PyQt4 checks each element of the collection.
You need to implement explicit QVector<Point> etc mapped types to specify the conversion behaviour you want rather than rely on the PyQt5 mapped type template.
Phil
More information about the PyQt
mailing list