Hi Christoph On Fri, May 13, 2011 at 9:32 AM, GOO Creations <[email protected]> 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 > > This error seems strange, since I've never included MyClass in the SIP files > and the only place MyClass is instantiated is in my cpp file (I didn't even > include the MyClass directory in the cmake file that handles the SIP files). > So I'm a bit confused of how Python gives an error on code that isn't > linked to SIP. > > 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. > > By the may: when I remove the template from MyClass and make everything by > default int, everything compiles and runs perfectly. > > Does anyone have an idea of why this is happening, or if I maybe have to > include something special in the cmake files? > > Thanks > > Chris >
I remember some discussions at the lisbon hackfest about templated c++ code and difficulties wrapping it with sip. Martin Dobias probably know more, but I would add that we generally avoid template programming in QGIS as it isnt very 'Qt' like, and also isnt very consistent with the rest of our api. Regards Tim > _______________________________________________ > Qgis-developer mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/qgis-developer > > -- Tim Sutton - QGIS Project Steering Committee Member (Release Manager) ============================================== Please do not email me off-list with technical support questions. Using the lists will gain more exposure for your issues and the knowledge surrounding your issue will be shared with all. Visit http://linfiniti.com to find out about: * QGIS programming and support services * Mapserver and PostGIS based hosting plans * FOSS Consulting Services Skype: timlinux Irc: timlinux on #qgis at freenode.net ============================================== _______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
