[Qt-interest] QTimer still fires after stop() AND delete

marc at mferland.net marc at mferland.net
Sat Oct 17 01:51:56 CEST 2009


Quoting Josiah Bryan <jbryan at productiveconcepts.com>:

> Hi All -
>
> I think I'm going crazy, but this really seems to be what is happening:
>
> I've got a QTimer that I set to trigger changing of a widget label. The
> user can also trigger the widget label using a button in the form. If
> the user changes the label before the timer times out, then my code
> calls the stop() method on the timer. However, the slot that is connect
> to the timer is STILL CALLED even after stop is called.
>
> Okay, I thought it was just my mind playing tricks. So, instead of just
> calling stop(), I stop(); disconnect(timer,0,this,0); delete timer;
> timer=0; ... and the slot connect to the timer is STILL called.
>
> I know its the timer because the slot being called is ONLY connected to
> that timer. Additionally, the gdb stack dump reports Qtimer::timerEvent
> and QTimer::timeout in the stack that calls the slot.
>
> How can that possibly be? Why is the slot being called even though I've
> stopped the timer?

This happened to me once, a thread was posting signals to another  
thread and sometimes after having stopped and deleted the thread, a  
signal could still come in from this "ghost" thread object.

You could maybe use an internal variable and check whether or not the  
slot has to process the events.

I think that Qt keeps the event objects inside the event list even  
though the sender has been destroyed.

Marc





More information about the Qt-interest-old mailing list