Is deleteLater() processed BEFORE other events posted by the object?



  • Well the title says it all, but for a real world example, suppose I initialize a QTcpSocket. When I am done with it, I want to delete it with code like this:

    @void terminateSocket()
    {
    socket->deleteLater();
    ...
    some_long_operation();
    }@

    In the rare (?) situation where a packet arrives when some_long_operation() is running, after the function finishes which event is processed sooner? Is it: 1. the socket is deleted and all its events and pending signals are discarded, or 2. first events are processed and signals emitted then the socket object is deleted? or is it something different?

    Another example can be a timer. Suppose the slot connected to its timeout() signal realizes that timer's job is done so it stops the timer and calls deleteLater() on it. What happens if another timeout() signal is emitted before the mentioned slot is finished executing? Is the timer deleted and the signal discarded, or does it call the slot again? (What if the signal-slot connection is not direct connection?)

    Sorry if the question is broad.


  • Moderators

    [quote author="Chromatix" date="1365492102"]Another example can be a timer. Suppose the slot connected to its timeout() signal realizes that timer's job is done so it stops the timer and calls deleteLater() on it. What happens if another timeout() signal is emitted before the mentioned slot is finished executing? Is the timer deleted and the signal discarded, or does it call the slot again? (What if the signal-slot connection is not direct connection?)
    [/quote]

    Connections are disconnected on destruction. So the slot won't get called on the destroyed object.
    Are you talking about calling a slot from another thread?



  • You didn't quite get me due to my poor way of asking questions. I want to know if this destruction happens before or after the emitted signal has been processed. (Actually I'm going to mention calling from other threads, too; but I think I mentioned non-direct connections too early. I leave it until an answer to the main question.)

    To reword the main question: When you call object->deleteLater() and the object has some pending events and signals (and probably more events arrive after this call), when the control returns to the event loop, are the pending events discarded, or deleteLater() waits until all of them have been processed? Does deleteLater() post some kind of event with a higher priority?




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.