[PyQt] Using own module in SIP interface as parameter

Stefan Dentro S.C.Dentro-1 at student.tudelft.nl
Mon Aug 16 11:25:43 BST 2010


I'm currently working on replacing a custom PyQt module with a custom
Qt module. Before I'm diving in I thought I'd create a HelloWorld
testcase. But for some reason I can't get it to work properly. My
question is, how should I create a single Python-SIP module containing
two classes in which one takes the other as parameter when
instantiating?

An overview of what I've got untill now:
Class A takes an object of class B as parameter (see a.cpp below).
I've included b.h in a.h in order for a to be able to see b. Both c++
modules compile and issuing ldd shows b is properly linked into a.
Since the SIP interface must also contain a description of this
constructor it also needs to know about both classes a and b.
Therefore I've included a.h and b.h in their respective SIP files.

But when I issue make on the SIP files I keep running into circular
import errors:
In file included from b.sip:7:
./b.h:3: error: redefinition of ‘class HW::B’
./b.h:3: error: previous definition of ‘class HW::B’
make: *** [sipAHWA.o] Error 1

Obviously that is because both a.h and b.h are included and a.h
includes b.h. But removing either an include or adding a %Import b.sip
makes me run around in circles. It's either a redefinition, or SIP
can't find the specification of B. What am I overlooking?

My files:
b.h
-----------------------------
namespace HW {
class B {
public:
       B();
};
}

b.cpp
-----------------------------
#include "b.h"
namespace HW {
int B() {
}
}

a.h
-----------------------------
#include "b.h"

namespace HW {
class A {
public:
       A(B b);
};
}

a.cpp
-----------------------------
#include "a.h"
namespace HW {
int A(B b) {

}
}

a.sip
-----------------------------
%Module A 0

namespace HW {
class A {

%TypeHeaderCode
#include <a.h>
%End

public:
       A(HW::B b);
};
};

b.sip
-----------------------------
%Module B 0

namespace HW{
class B {

%TypeHeaderCode
#include <b.h>
%End

public:
       B();
};
};

helloworld.sip
-----------------------------
%Module HelloWorld

%Include b.sip
%Include a.sip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100816/f8d37d83/attachment.html>


More information about the PyQt mailing list