[Qt-interest] please help me with this problem
Nikos Chantziaras
realnc at arcor.de
Tue Dec 8 01:56:37 CET 2009
On 12/07/2009 08:06 PM, Yifei Li wrote:
> Hi folks,
>
> In my thread's run() method, signal displayMessage(QString) is emitted and the signal is connected to a slot setMessage(QString) in a QGraphicsScene object (using direct connection)
>
> // run method looks like this:
> void run()
> {
> sleep(2);
> emit displayMessage("hello 1");
> sleep(2);
> emit displayMessage("hello 2");
> sleep(2);
> emit displayMessage("hello 3");
> }
>
> // Here is what setMessage(QString) looks like:
> void setMessage(QString msg)
> {
> m_message = msg; // save the message
> update();
> }
>
> The message is then displayed in drawForegound method
>
>
> However, my problem is 'hello1' and 'hello2' don't show up at all, only 'hello3' does.
>
> My guess is that update() queues the paint event and several paint events are merged into one due to optimization, so what should I do make those three messages displayed one after another?
I think your problem is that sleep() blocks. That means, the
application actually "hangs" for 2 seconds between each sleep() with no
chance to update the display.
You should use timers instead of sleep(). See
http://doc.trolltech.com/4.6/qtimer.html#details on how to emit signals
with a time delay or periodically.
More information about the Qt-interest-old
mailing list