Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    4
    2702
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Chromatix last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        [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?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • C
          Chromatix last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • P
            prady_80 last edited by

            May be "this":http://stackoverflow.com/questions/4888189/how-delete-and-deletelater-works-wrt-to-signals-and-slots-in-qt helps.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post