[Qgis-developer] Template programming in QGIS

Martin Dobias wonder.sk at gmail.com
Fri May 13 05:58:37 EDT 2011


On Fri, May 13, 2011 at 9:32 AM, GOO Creations <goocreations at gmail.com> wrote:
> Hi all
>
> I'm currently writing C++ code that I want to use via Python with SIP. The
> following is a skeleton for my code:
>
> template<class T>
> class MyClass
> {
>     MyClass(QString s);
>     T* calculate();
> }
>
> class B
> {
>     B();
>     void doStuff();
> }
>
> void B::doStuff()
> {
>     MyClass<int> var("");
>     int *var2 = var.calculate();
> }
>
> The only class I've included in my SIP file is class B (and not class A).
> Everything compiles correctly, but when QGIS starts, I get a Python error:
>
>   File "/home/goocreations/apps/share/qgis/python/qgis/utils.py", line 283,
> in _import
>     mod = _builtin_import(name, globals, locals, fromlist, level)
> ImportError: /home/goocreations/apps/lib/libqgis_mylib.so.1.7.0: undefined
> symbol: _ZN15MyClassIiEC1E7QString

>From the error I would expect that the body of the MyClass(QString s)
constructor is missing: you have only declared it.


> So, I've though that creating a SIP binding for MyClass may resolve the
> issue, but I can't figure out how I would use templates in SIP.

SIP refers to template classes as "mapped types". Here you can find
some documentation:
http://www.riverbankcomputing.co.uk/static/Docs/sip4/directives.html#directive-%MappedType

Regards
Martin


More information about the Qgis-developer mailing list