[PyKDE] Re: How to embed Python in C++

David Boddie david at boddie.org.uk
Tue Mar 28 00:08:38 BST 2006


On Saturday 25 March 2006, I wrote:
> 
> On Fri, 24 Mar 2006 17:40:00, Eric Jardim wrote:

[Defining a factory function]

> It's easy to define a single function to do this:
> 
>     PyRun_String("from PyQt4 import QtGui\nimport sip\n"
>                  "def __embedded_factory__create__(parent = None):\n"
>                  "    global plugin\n"
>                  "    print \""CLASS_NAME"\"\n"
>                  "    plugin = "CLASS_NAME"(parent)\n"
>                  "    return sip.unwrapinstance(plugin)\n",
>                  Py_file_input, pyDict, pyDict);
> 
>     PyObject *pyFactory = PyDict_GetItemString(pyDict,
>                           "__embedded_factory__create__");
> 
> This one creates a single instance of a plugin, typically an instance
> of a SIP-wrapped class.

Just don't do what I did and explicitly Py_XDECREF the factory function
object. :-(

Since I fixed that obvious mistake, things have become a lot easier, and
I've uploaded a snapshot of my current attempts to integrate Qt's meta-object
system with PyQt4:

http://www.boddie.org.uk/david/Projects/Python/Qt/Software/Patches-20060328.tar.gz

Currently, I've got some sort of property support enabled, though there are
some recently introduced issues with scanning class dictionaries for
properties that I'll have to try and work around. My next goal is to add
support for named signals and slot, ideally by getting PyQt's existing
infrastructure to do the hard work.

David




More information about the PyQt mailing list