This is an expected limitation due to how Qt works. Even your C++ Qt application is required to have the GUI run in a single thread. You can do work in other threads and emit signals across thread boundaries, but the event loop executes single-threaded.
Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread. http://developer.qt.nokia.com/doc/qt-4.8/threads-qobject.html Nathan 2012/2/8 Sébastien Sablé Sablé <sa...@users.sourceforge.net> > Hi Alberto, > > thank you for your answer! > > The event loop is actually running in a separate thread. > I managed to get the example running by adding a call to processEvents: > > from PySide import QtGui > > from PySide import QtCore > > wid = QtGui.QLabel("Whatever") > > wid.resize(450, 150) > > wid.setWindowTitle('Simple') > > wid.show() > > while True: > > QtCore.QCoreApplication.processEvents() > > > I think I will use this workaround for the moment. > It is not clear to me however if this is an expected limitation due to how > Qt works with threads or if this is a bug in PySide. > > I would appreciate if someone could come with a cleaner solution or tell > me if I should fill a bug request. > > best regards > > -- > Sébastien Sablé > > > Le 8 février 2012 15:12, Alberto Soto <alberto.s...@lmsintl.com> a écrit : > > Hi Sébastien, >> >> This sounds to me like an event loop problem. >> >> The MessageBox::question static method creates its own event loop >> and then returns. So that's probably the reason it works. >> >> Are you creating the QLabel widget in the same thread as the GUI >> application thread? I seem to remember a limitation, when working >> on multithread Qt applications with a GUI. >> From the "Rapid GUI Programming with Python and Qt" book: >> PyQt applications always have at least one thread of execution, the >> primary >> (initial) thread. In addition, they may create as many secondary threads >> as >> they need. However, if the application has a GUI, the GUI operations, such >> as executing the event loop, may only take place in the primary thread. >> -- chapter 19. Multithreading. >> >> Hope this helps! >> >> >> Alberto SOTO >> >> >> _______________________________________________________________________________________________________ >> From: pyside-boun...@lists.pyside.org [mailto: >> pyside-boun...@lists.pyside.org] On Behalf Of Sébastien Sablé Sablé >> Sent: mercredi 8 février 2012 11:35 >> To: pyside@lists.pyside.org >> Subject: [PySide] PySide in a C++ application using Qt >> >> Hi, >> >> I am using PySide 1.1.0. And I would like to use it inside a C++ >> application that already uses Qt and provides an embedded Python >> interpreter. >> >> I tried something like that: >> >> from PySide import QtGui >> app = QtGui.QApplication.instance() >> print app >> wid = QtGui.QLabel("Whatever") >> wid.resize(450, 150) >> wid.setWindowTitle('Simple') >> wid.show() >> >> >> Since there is already a running QApplication, I do not create a new one. >> There is also a running event loop in another thread since the application >> interface reacts. >> >> This code snippet works partially: >> a new window is created, with a "simple" title, but the text inside it is >> never displayed and the windows does not react at all: >> I can't move it, resize it or anything. >> >> If I call "wid.repaint()", the text inside the window is correctly >> refreshed; however the window still does not react to any event. >> >> I also tried to create a message box like that: >> QtGui.QMessageBox.question(wid, 'Message', "Existing app: %r" % app, >> QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) >> >> This time the message box reacts correctly: it is correctly displayed, it >> shows the existing QApplication object and the buttons react. >> >> A screenshot of the result can be seen here: >> http://dl.free.fr/dey2Tzig3 >> >> It seems as if the QLabel I created does not receive any event. >> Do you have any idea of how I can fix that? Should I open a bug >> concerning this behavior? >> >> Thanks in advance >> >> Sébastien Sablé >> >> >> > > _______________________________________________ > PySide mailing list > PySide@lists.pyside.org > http://lists.pyside.org/listinfo/pyside > >
_______________________________________________ PySide mailing list PySide@lists.pyside.org http://lists.pyside.org/listinfo/pyside