[PySide] Typedef template containers

John Cummings jcummings2 at users.sf.net
Thu May 31 21:30:21 CEST 2012

I am sending this message to the list in case it can save anyone else hours of 
frustration. If someone knows a better way to handle typedef'd template 
containers as arguments, please let me know.

If you have a typedef template container (Qt-based, STL-based or your own custom 
one) and functions (or methods) such as:

    QVector<double> FooType;
    FooType returnFoo();
    void callWithFoo(FooType foo);

Your typesystem XML file will need to have the following lines:

    <function signature="returnFoo()" />
    <function signature="callWithFoo(QVector<double>)" />

Note the difference between returning a typedef'd container and passing one as 
an argument. Namely, Shiboken is fine with returning the typedef directly since 
you don't have to specify it in the typesystem XML file. However, if you are 
passing a typedef'd container into a function (or method), you must specify the 
underlying type (and convert '<' to "lt;" and '>' to "gt;"). If you try to use 
"FooType" instead of specifying the underlying type, you will get a warning 
message from Shiboken along the lines of:  "Global function 'callWithFoo(FooType 
foo)' is specified in typesystem, but not defined. This could potentially lead 
to compilation errors." It might compile but callWithFoo will not be accessible 
from python. Adding various "object-type" or "value-type" tags won't help either.

You will also need a "container-type" conversion tag. If you are using QVector, 
then you can just point at the existing conversion logic by adding the following 
to your typesystem XML file:

    <load-typesystem name="typesystem_core.xml" generate="no" />
    <load-typesystem name="typesystem_templates.xml" generate="no"/>

You can also look at those two files as an example for handling other container 

As I said, I hope this saves someone else some time. It would be a nice feature 
if Shiboken could understand the typedefs for you instead of you having to 
manually make the substitution.

John Cummings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120531/f36e410e/attachment.html>

More information about the PySide mailing list