[PyQt] Re: SIP errors: class inherits from std::list

Jim Bublitz jbublitz at nwinternet.com
Mon Sep 3 16:32:33 BST 2007

On Monday 03 September 2007 02:30, Ovidiu Ciule wrote:
> Hello,
> This is a relaunch of the earlier mail. I have found a work around: I
> define AccountList as a MappedType, still std::list<Account>, but not
> a template. The sip file includes %ConvertToTypeCode and
> %ConvertFromTypeCode  This is messy though. So I'm still hoping
> someone (Phil?) could clear the template issue. Oh, and the typedef
> problem.
> For reference, here's the original text:
> I have a class, AccountList, that inherits from std::list. When trying
> to generate bindings for it, SIP reports errors. I'm using SIP 4.5 on
> Ubuntu. I'm downloading SIP 4.7 now, but I don't think it'll help, as
> the change log doesn't mention anything relevant about templates.
> Here's the the .sip file:
> AccountList.sip
> class AccountList : std::list<Account> {
> %TypeHeaderCode
> #include <coipmanager_base/account/AccountList.h>
> %End
> public:
> ... various boring methods
> };

One way to handle it is to ignore the inheritance:

class AccountList

and the then add the Python list methods (__len__, __setItem__, __del__, slice 
operations, etc) with handwritten code. You can steal it all from PyQt - for 
example sip/QtCore/qstringlist.sip (or sip/qt/qstringlist.sip in PyQt3), 
which is a similar class to yours. 

You can also include any methods that AccountList has - even those inherited 
from std::list if they make sense to include. sip just won't automatically 
include std::list's methods in this case.

AccountList then becomes effectively a subclass of Python's list class, which 
is generally more comfortable for Python programmers anyway.


More information about the PyQt mailing list