| Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Dear all, I am writing a application with two thread : - one for the Qt interface (a subclass of QMainWindow) - one for a long computation (a standard java object which implement the Thread interface) This second thread call sometimes the object of the first thread to update information about the progress of the computation (with the setText() method of a TextEdit widget). When the call of the method to refresh information occurs Qt-Jambi throws me the following error : QObject: Cannot create children for a parent that is in a different thread. How could i force the second thread to use the event dispatcher of the first thread or how could i easily make the information progress work ? Laurent.
On Saturday 04 November 2006 00:08, Laurent Jourdren wrote: > Dear all, > > I am writing a application with two thread : > > - one for the Qt interface (a subclass of QMainWindow) > - one for a long computation (a standard java object which implement > the Thread interface) > > This second thread call sometimes the object of the first thread to > update information about the progress of the computation (with the > setText() method of a TextEdit widget). When the call of the method > to refresh information occurs Qt-Jambi throws me the following error > : > > QObject: Cannot create children for a parent that is in a different > thread. > > How could i force the second thread to use the event dispatcher of > the first thread or how could i easily make the information progress > work ? I've been able to do this using a connect. If you connect the default will check if both the objects you are connecting are in different threads (since each QObject has an owning thread) and if so it will use a queue for transmitting the data. This means in effect that you should replace your setText() call (which already is a slot) with a connect and an emit of the updated text. Hope that helps. -- [ signature omitted ]
Attachment:
pgpYjrxC0wFBu.pgp
Description: PGP signature
> On Saturday 04 November 2006 00:08, Laurent Jourdren wrote: > > Dear all, > > > > I am writing a application with two thread : > > > > - one for the Qt interface (a subclass of QMainWindow) > > - one for a long computation (a standard java object which implement > > the Thread interface) > > > > This second thread call sometimes the object of the first thread to > > update information about the progress of the computation (with the > > setText() method of a TextEdit widget). When the call of the method > > to refresh information occurs Qt-Jambi throws me the following error > > : > > > > QObject: Cannot create children for a parent that is in a different > > thread. > > > > How could i force the second thread to use the event dispatcher of > > the first thread or how could i easily make the information progress > > work ? > > I've been able to do this using a connect. > If you connect the default will check if both the objects you are > connecting are in different threads (since each QObject has an owning > thread) and if so it will use a queue for transmitting the data. > > This means in effect that you should replace your setText() call (which > already is a slot) with a connect and an emit of the updated text. > > Hope that helps. Thanks for your help, Now, I use signals and slot and all works fine. It's the first time that I use Qt, so with unfinished translation to Java of the documentation, I'm sometimes a little lost. Qt-Jambi is really a great tool !!! Thanks also Thomas for all your work on KOffice and KDE. Laurent.