[PyKDE] Help with SIP

Jim Bublitz jbublitz at nwinternet.com
Mon Oct 2 05:13:15 BST 2006

On Sunday 01 October 2006 18:44, Christoph Spoerri wrote:
> Hi there,

> I just signed up to the list here, since I'm trying to create a python
> wrapper for an QT application. As you can imagine I'm running into
> problems since I'm new to SIP and its functions.

> The first question I'm having is how I need to deal with classes that
> depend on each other. Let's assume I have class A which returns
> instances for class B and C. Do I need to create .sip file for B and C
> first (b.sip/c.sip)? Or can I just create the a.sip file?

"Returns instances" to where? If B and C are not visible in the sip file for A 
and not wanted in Python, then you don't need a .sip file for B and C. For 

C++    a.h

class A
	       A ();
   bool   doSomething (int x);
   B *     createB ();
   C *     createC  ();

sip file   a.sip
class A
#include <a.h>

	       A ();
   bool   doSomething (int);

On the other hand, if you want to call method "createB" in Python, then B 
needs a .sip file (but only if it returns B; if it's 

void createB ();

sip won't care.) However, C++ will want to see the definitions for B and C 
when it reads the h file - you need to make sure their h files (if they're 
not in a.h) are included during compilation. You can put them in the 
%TypeHeaderCode block if necessary. sip doesn't read h files and nothing in 
the cpp files makes a difference (as far as sip goes).

If you have a situation like:

class A : public B

you either need to do bindings for B, or in the sip file:

class A

and ignore the base class (but then you won't get the base class's methods 

> The second questions is in regard of compiling the classes. In case I
> need all three classes, what's the easiest way to compile them all at
> the same time?

If they're small enough (for your convenience), you can put all of the classes 
in a single sip file. Alternatively, you can create a single "top level" sip 
file and just pass that file to sip:


// the name you import in Python "import someName"
// Only one of these per module, so if it's here, don't
// put it in a.sip, b..sip or c.sip
%Module  someName

%Import qt   // if a,b, or c depend on qt in their sip files

%Include a.sip
%Include b.sip
%Include c.sip

The sequence is unimportant - sip collects all symbols in a module and then 
checks that they're all defined, unlike C++, where definitions are sequence 

Take a look at how PyQt/sip/qt/qtmod.sip is set up. There are also sip docs in 
the sip tarball (in the doc/ directory). You can get the tarball from 


More information about the PyQt mailing list