[PyQt] C++ and embedded python, how to share gui thread?

Patrick Stinson patrickkidd.lists at gmail.com
Wed May 16 21:41:37 BST 2007

there is only one QApplication. Even in apps where you are writing a
graphical plugin that will be used in a native event loop, you have to
manage one QApplication instance. So, if your C++ app created a
QApplication then you don't have to worry about it just create the
PyQt widgets at will. This will all work the best if the qt lib you
are using is a shared library or dll, because you don't want to link
it in twice; once with the C++ app and once with the PyQt4 module.

I Hope that helps a little. I have more info on how I did the same thing here:


On 5/16/07, Michael Olberg <michael.olberg at chalmers.se> wrote:
> Dear all,
> I have a scientific application programmed in C++ with the Qt widget set. I have
> embedded a Python interpreter to allow me to control the application via
> scripts. I can even import the python-qt bindings in those scripts and create
> graphical dialogs. So at present everything works(!) as expected.
> However, this works with an old setup of Debian sarge and the
> python2.3-qt3_3.11-4_i386.deb package. A number of upgrades have happened since
> then, with python, with qt, and even with Debian. With newer versions
> non-graphical scripts still work, but any attempt to open Qt dialogs from the
> embedded python interpreter hangs the application.
> It appears to me that this has to do with how later versions of the python-qt
> package access the main Qt GUI thread, which in my case is already started by
> the underlying C++ application.
> I wonder if this is documented somewhere, with an example on how to start the
> python interpreter so that the C++ and python can share the same Qt GUI? I'd
> very much like to upgrade my system without breaking this application, which I
> use for daily work.
> any info appreciated,
> Michael
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Patrick Kidd Stinson

More information about the PyQt mailing list