[PyQt] downcast a base class to its template subclass

Qin Shen jeanshen at tippett.com
Tue Nov 2 00:26:41 GMT 2010


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?


The files look like this:

In [BaseEntity.sip]
--------------------------------------------
class BaseEntity
{
%TypeHeaderCode
    #include <BaseEntity.h>
%End

%ConvertToSubClassCode
    sipType = sipFindType(sipCpp->classType());
%End

public:
    ....

}



[CustomEntity.h]
-------------------------------------------
template <int ID>
class CustomEntity : BaseEntity
{
public:
    CustomEntity();
    virtual ~CustomEntity();

    std::string classType() const
    {
        std::ostringstream nameStream;
        nameStream << "CustomEntity" << std::setfill('0') << 
std::setw(2) << ID;
        return nameStream.str();
    }

    ... // more stuff here
}


[CustomEntity.sip]
-------------------------------------------
template <ID>
class CustomEntity : BaseEntity
{
%TypeHeaderCode
    #include <CustomEntity.h>
%End

public:
    CustomEntity();
    virtual ~CustomEntity();

    std::string classType() const;

    ... // more stuff here
}



Thanks a lot,

-Jean





More information about the PyQt mailing list