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. Disconnect QObject signal/slot in Qt5
Qt 6.11 is out! See what's new in the release blog

Disconnect QObject signal/slot in Qt5

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Ramakanth
    wrote on last edited by
    #1

    In Qt 4.8.x, As disconnect QObject is called explicitly since disconnectNotify() is not invoked for graceful cleanup, Is it recommended to remove all disconnect of QObject signals/slots associated before deleting QObject since disconnectNotify is invoked automatically in Qt5 or ok to keep disconnect()?

    Below snippet is used in Qt 4.8.x,
    disconnect();
    delete QObject;

    JKSHJ 1 Reply Last reply
    0
    • R Ramakanth

      In Qt 4.8.x, As disconnect QObject is called explicitly since disconnectNotify() is not invoked for graceful cleanup, Is it recommended to remove all disconnect of QObject signals/slots associated before deleting QObject since disconnectNotify is invoked automatically in Qt5 or ok to keep disconnect()?

      Below snippet is used in Qt 4.8.x,
      disconnect();
      delete QObject;

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @Ramakanth said in Disconnect QObject signal/slot in Qt5:

      ok to keep disconnect()?

      It is OK to keep disconnect().

      delete QObject;

      It is best not to call delete on QObjects. Use QObject::deleteLater() to avoid crashes in your code.

      When you use QObject::deleteLater(), signals and slots are automatically disconnected and the object will be deleted when it is safe.

      In Qt 4.8.x, As disconnect QObject is called explicitly since disconnectNotify() is not invoked for graceful cleanup

      This sounds wrong to me. Where did you hear this from?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      R 1 Reply Last reply
      3
      • JKSHJ JKSH

        @Ramakanth said in Disconnect QObject signal/slot in Qt5:

        ok to keep disconnect()?

        It is OK to keep disconnect().

        delete QObject;

        It is best not to call delete on QObjects. Use QObject::deleteLater() to avoid crashes in your code.

        When you use QObject::deleteLater(), signals and slots are automatically disconnected and the object will be deleted when it is safe.

        In Qt 4.8.x, As disconnect QObject is called explicitly since disconnectNotify() is not invoked for graceful cleanup

        This sounds wrong to me. Where did you hear this from?

        R Offline
        R Offline
        Ramakanth
        wrote on last edited by
        #3

        @JKSH said in Disconnect QObject signal/slot in Qt5:

        It is best not to call delete on QObjects. Use QObject::deleteLater() to avoid crashes in your code.

        Sorry for the delayed response. Thanks for your response.
        There is a bug in Qt 4.8.x https://bugreports.qt.io/browse/QTBUG-4844. Due to which the statement, A signal-slot connection is removed when either of the Qt objects involved are destroyed” is incorrect in Qt 4.8 but is fixed in Qt 5.0.

        Ok shall retain the existing disconnect() statements used in Qt 4.8.x and call deleteLater() instead. In Qt 5.x, we donot have to call disconnect QObject as it is disconnected automatically,right?

        JKSHJ 1 Reply Last reply
        1
        • R Ramakanth

          @JKSH said in Disconnect QObject signal/slot in Qt5:

          It is best not to call delete on QObjects. Use QObject::deleteLater() to avoid crashes in your code.

          Sorry for the delayed response. Thanks for your response.
          There is a bug in Qt 4.8.x https://bugreports.qt.io/browse/QTBUG-4844. Due to which the statement, A signal-slot connection is removed when either of the Qt objects involved are destroyed” is incorrect in Qt 4.8 but is fixed in Qt 5.0.

          Ok shall retain the existing disconnect() statements used in Qt 4.8.x and call deleteLater() instead. In Qt 5.x, we donot have to call disconnect QObject as it is disconnected automatically,right?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Ramakanth said in Disconnect QObject signal/slot in Qt5:

          Qt 5.x, we donot have to call disconnect QObject as it is disconnected automatically,right?

          Yes.

          You can write some simple test code double-check.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1

          • Login

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