[PyKDE] Using sip with embedded Python

David Boddie david at boddie.org.uk
Mon Aug 11 22:33:01 BST 2003


After lots of experimentation, I've come to the conclusion that I'm
fundamentally misunderstanding how to use various siplib functions.

In particular, I thought I knew how to use the sipMapCppToSelf function,
but it appears that the various sipClass_ pointers I'm using are not
initialised. This might explain the crashes I've been encountering.

In my library I do the following:

1. I initialise the Python interpreter and import a Python module.

2. The Python module imports all the modules it needs, including the
   qt module (which is linked at compile time, but only resolved at runtime).
   (I'm also linking against libsip.so, too).

3. I attempt to convert a QWidget* (the "parent" variable) to a Python object
   using

   pArg1 = sipMapCppToSelf(parent, sipClass_QWidget);

   (pArg1 is a PyObject*)

   When parent is NULL, this succeeds; otherwise it fails. I discovered
   that sipClass_QWidget has the value 0 so suspected that sipMapCppToSelf
   catches the bad parent value normally but gets confused when it has to
   deal with a NULL sipClass_QWidget value.

The only thing I'm doing to make sipClass_QWidget visible to my library is
to declare

extern SIP_IMPORT PyObject *sipClass_QWidget;

Am I supposed to perform some sort of initialisation?

Sorry if this is mentioned somewhere in the sources or available
documentation. If it is then I'd be happy to be redirected to it.

Thanks in advance,

David




More information about the PyQt mailing list