[PyQt] casting issues

Diez B. Roggisch deets at web.de
Thu Sep 17 00:28:52 BST 2009


when wrapping a C++-library with SIP ( 4.9-snapshot-20090821) I run into 
a couple of issues.

First of all, the library I wrap has a hierarchy of classes (all 
descending from ISceneNode) which I wrapped.

Now through an instance of a so-called ISceneManager, I can access 
instances of the current scene-graph which are ISceneNode-instances. 
Consequently, the signature for one of the accessory-methods looks like 

   ISceneNode *getSceneNodeFromID(int)

So far, so good.

Now problem number one comes up: I *know* a certain node is of type e.g. 
IMeshSceneNode. But when I access it via the above method, all I get is 
an ISceneNode. My C++-foo is rusty, and I know that RTTI isn't always 
available - I just wonder: is there a way for SIP to figure out the 
actual type of the instance returned, and wrap it accordingly? If yes, 
what do I need to do to enable that feature?

However, the library in question offers a getType()-call on ISceneNodes, 
and this I can use to write casting-code myself.

So I tried sip.cast, and that's my second issue for today: this 
dramatically segfaults for me.

What works though is sip.unwrapinstance and sip.wrapinstance called in 
succession. The subsequent tinkering with the nodes shows that it 
actually works.

So the question is - why does sip.cast bomb? I use it like this:

  sip.cast(terrain, scene.IMeshSceneNode)



More information about the PyQt mailing list