Qt Forum

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

    Unsolved Signal behaviour when object goes out of scope.

    Wiki Discussion
    2
    3
    781
    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.
    • S
      Shivendra Pratap Singh last edited by

      I am running a single-threaded application on 2 monitors, these monitors are touch monitors and they are running the same instance of the application.
      Question is what will happen when somebody performs different operations on these 2 monitors at the same time.
      Let me paint a scenario
      There is a pop up on both the monitors with options Save, Don't Save, Cancel for some data.
      Now somehow users manage to fire Save and Don't Save signal at the same time.

      Suppose Save signal calls the SLOT which saves the data and jumps to the next screen i.e. its object goes out of scope.
      Now in the queue, we have Don't Save Signal which has some other SLOT to call but its object is already out of scope.
      Main issue is here what will happen/ how the application is going to behave??

      Chris Kawa 1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators @Shivendra Pratap Singh last edited by Chris Kawa

        Hi, welcome to the forum.

        @Shivendra-Pratap-Singh said in Signal behaviour when object goes out of scope.:

        Now somehow users manage to fire Save and Don't Save signal at the same time.

        First of all, if the app is single threaded, there's no such thing as "at the same time". Those calls will be serialized no matter what.
        Without additional flags a connection on a single thread will call the slot immediately, so basically it's like a function call (with additional minor overhead). When QObject is deleted all connections to it are severed.

        So summing those factors in, if a slot connected to first signal deletes the object, by the time the second signal is fired the object is already gone and the signal is no longer connected to it. If it was the only connection to that signal emitting it will do nothing.

        1 Reply Last reply Reply Quote 3
        • S
          Shivendra Pratap Singh last edited by

          Hi, @Chris-Kawa Thanks for your quick reply.

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