[PyQt] Problems with wrapping complex types using typedefs

Phil Thompson phil at riverbankcomputing.com
Fri Jul 5 10:55:17 BST 2013


On Fri, 5 Jul 2013 17:41:21 +0800, "Casper Ti. Vector"
<caspervector at gmail.com> wrote:
> For example, assuming all example use this header:
>> %Module test
>> %ModuleHeaderCode
>> #include "test.h"
>> %End
>> %Include types.sip // Where map, pair and vector are wrapped.
> 
> This code:
>> std::map<std::pair<int, int>, std::vector<unsigned long> > Test;
> fails because sip complains:
>> sip: Test has an unsupported type - provide %GetCode and %SetCode
> 
> while this code:
>> typedef std::pair<int, int> cell;
>> typedef std::vector<unsigned long> idxx;
>> std::map<cell, idxx> Test;
> fails because the compiler complains like:
>> error: 'sipType_cell' was not declared in this scope
>> error: 'sipType_idxx' was not declared in this scope
> 
> I searched Google for `python sip typedef' and found this message:
>
<http://www.riverbankcomputing.com/pipermail/pyqt/2011-January/029111.html>
> It seems that adding something like:
>> #define sipType_cell sipType_std_pair_1800_1800
>> #define sipType_idxx sipType_std_vector_2100
> to the `%ModuleHeaderCode' section make everything runs well.
> 
> However, this trick seems quite unreliable because these magic numbers
> (1800, 2100, etc.) might vary from version to version.  So is there any
> elegant way to wrap these types?
> 
> In addition, I personally think it is favourable to generate `sipType's
> for typedefs, because this can greatly simplify efforts on wrapping
> complex template types, such as those in my examples.

See...

http://pyqt.sourceforge.net/Docs/sip4/c_api.html#sipFindType

Phil


More information about the PyQt mailing list