[PyQt] Problems with accessing embedded python objects in QT App
Jamie Riotto
jamie.riotto at gmail.com
Sun Dec 6 00:01:48 GMT 2009
I am trying to constuct a simple empbedded Python app. Basically it is
a MainWindow with two
widgets in its central layout. The left widget is an openGL Viewer,
and the right widget is a QTextEdit
whose text is sent to a python interpreter upon a button push.
My app is linked with a static c++ lib of graphic primatives, like
constuct a cube and so on, which I've also
wrapped with SIP and have generated a GraphicPrimatives.pyd file.
When I run my app, I import the GraphicPrimatives.pyd file into my
python interpreter
and create a graphics object (no problem), and I'd like to display the
graphics object on the openGL side.
At first, I assumed that both the c++ side and the python side would
point to the same library instantiation,
but that appears not to be the case. For instance, I created a
singleton class in the graphics library. If I
call the singleton class from the C++ side, I see correct
initialization, but if I then call the singleton class from
the python side, I get a 2nd initialization (i.e. they are not
pointing back to the same static object in memory).
So my question is:
1) How do I fix the library problem above (i.e. how do I have both the
c++ and python interpreter pointing to the same
library.
or
2) How do I pass or fetch a pointer to the object in python space?
I've tried using something like
Py_Initialize();
PyRun_SimpleString("from GraphicPrimatives import *");
PyRun_SimpleString("rootObject = Object()");
PyObject* mainModule = PyImport_AddModule("__main__");
pyDict = PyModule_GetDict(mainModule);
PyObject* pyRootObject = PyDict_GetItemString(pyDict, "rootObject");
But simply trying to cast the pointer like:
(Object *)pyRootObject
produced incorrect results.
Any help would be greatly appreciated. Thanks - Jamie Riotto
More information about the PyQt
mailing list