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&lt;double&gt;)" />

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 types.

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
_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to