[PyQt] PyQt in embedded python (C++/Qt Application)
Andreas Pakulat
apaku at gmx.de
Fri Jan 13 15:13:25 GMT 2012
On 13.01.12 15:09:06, Marc Gronle wrote:
> Hello everybody,
>
> I am developing a C++/Qt Application, where we integrated python as scripting engine. I would like to offer the possibility to write PyQt-Scripts in order to generate user-defined interfaces.
>
> In the present case, the python interpreter runs in its own thread within the C++-framework. If I execute the following demo script in Debug-mode (Visual Studio, Windows 7)
>
> -------
> from PyQt4 import QtCore, QtGui
> app =QtGui.QApplication([])
> ... (create window, show it...)
> app.exec_()
> -------
>
> it works (even if python is executed in a second thread). However in Release-mode the line app=QtGui.QApplication([]) crashes with the warning
>
> WARNING: QApplication was not created in the main() thread.
I don't think this will work, QApplication only supports a single
instance per process (the C++ one) and even if creating another works
sometimes you may run into crashes, weird behaviour etc. In addition
you'd need to integrate the event-loops of the two QApplications
somehow.
Did you try just creating a QPushButton and calling its show() function?
Another option might be to use the multiprocessing module to run the
plugins as separate processes, but of course that makes communication a
bit more involved.
Andreas
More information about the PyQt
mailing list