Qt-interest Archive, November 2007
How to safely update QTextEdit using append?
Message 1 in thread
Hi,all
I'm writing a soft using QTextEdit to log something, I have several
threads working background
these threads will produce some messages ,I use QTextEdit::append to
log these messages
on the QTextEdit,But I always get these error messages:
QPixmap::operator=: Cannot assign to pixmap during painting
then application crashes.
What's the causation?
How can I fix it?
How to safely update QTextEdit?
Thanks
--
[ signature omitted ]
Message 2 in thread
Hi,
> I'm writing a soft using QTextEdit to log something, I have several
> threads working background
> these threads will produce some messages ,I use QTextEdit::append to
> log these messages
> on the QTextEdit,But I always get these error messages:
> QPixmap::operator=: Cannot assign to pixmap during painting
> then application crashes.
> What's the causation?
> How can I fix it?
> How to safely update QTextEdit?
Don't update QTextEdit from threads. Just update it from the GUI threa:
http://doc.trolltech.com/4.3/threads.html#qobject-reentrancy
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.
In practice, the impossibility of using GUI classes in other
threads than the main thread can easily be worked around by
putting time-consuming operations in a separate worker thread
and displaying the results on screen in the main thread when
the worker thread is finished. This is the approach used for
implementing the Mandelbrot and the Blocking Fortune Client
example.
--
[ signature omitted ]