Access UI control from another thread
Environment: QT on S60
Test application: an UI dialog app. It has only one UI control on the dialog, a text edit. After the dialog displayed, I fork a new thread, derived from QThread. While the thread running, it need append some text to the text edit. So I call QTextEdit::append("123"). Expected result is that "123" is displayed without error. But actual result is, "123" is displayed, but immediately the thread got a panic 3. Debug info shows that the panic happens before return from append(). I know that S60 does not support such updating cross thread. But is it possible in QT for S60? Thanks very much for any reply.
PS: I have tried disable/enable updating before/after append(), but still panic.
Working with UI from other threads is not a good idea I think. You should better create a slot in main thread and execute it via signal-slot mechanism or invokeMethod() from child thread.
Never, ever, touch the UI from outside your UI thread, in any version of Qt. Queued signal/slots (or invoke methods, basically the same) or using custom events posted to the correct event loop are the only save ways to do this.
Thanks very much. The signal/slot resolve my problem.