Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is deleteLater() processed BEFORE other events posted by the object?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.0k Views
  • 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 Offline
    C Offline
    Chromatix
    wrote on last edited by
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      [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
      0
      • C Offline
        C Offline
        Chromatix
        wrote on last edited by
        #3

        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
        0
        • P Offline
          P Offline
          prady_80
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved