On Tue, 2 Nov 2010 10:55:51 -0700, Qin Shen <[email protected]> wrote: > Hi Phil, > > Phil Thompson wrote: >> On Mon, 1 Nov 2010 17:26:41 -0700, Qin Shen <[email protected]> wrote: >> >>> Hi, >>> >>> In my non-template base class' .sip file, I used %ConvertToSubClassCode >>> directive >>> to downcast the base class type to its sub-class. If the sub-class is >>> not a template, >>> it all works fine. Now I need to derive a template sub-class from the >>> base class, >>> the sipFindType() won't work because there isn't any Python class >>> implemented >>> for the templated sub-class. What should I do in this case? >>> >> >> So how is the template sub-class implemented in Python? Your >> %ConvertToSubClassCode will need to explicitly check for the template >> sub-class and return the appropriate Python type. >> > The .sip file of the template sub-class is based on its C++ .h header file. > Its implementation in the .sip file has been omitted since I thought I > don't > need to put any implementation in the .sip file as its C++ header file has > been properly included. > > When you asked how is the template sub-class implemented in Python, did you > mean that I need to put the C++ style implementation in .sip as well? > > Do I need to use %MappedType to convert the template sub-class to/from a
> Python > type. For a non-template class, sip usually generates a .cpp file for it > as well > as a corresponding sipType_BLAH. In the case of a template class, neither > was generated. I don't see a direct type match between a Python type and > any > specialization of the template sub-class, and no sipType_ is generated for > the template class, how am I supposed to convert the type? Any C++ template must eventually be implemented using a %MappedType - that's where you decide what Python type will be used to represent the C++ type. > Do you have any example on this? There are lots of examples in PyQt - qlist.sip is probably the most comprehensive. Phil _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
