Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105023

QObject::findChildren<T*> returns an unexpected result, if the Q_OBJECT macro is missing in the declaration of T

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.7.1, 6.8.0 FF
    • 6.3.1
    • Core: Object Model
    • None
    • All
    • ce2585d0e (dev), 9c1752d7b (6.7), 4c31b2ba6 (master)

    Description

      QObject::findChildren<T*> returns an unexpected result, if the Q_OBJECT macro is missing in the declaration of T.

      In the attached example the Q_OBJECT macro is commented out from the declaration of class Derived (derived from QObject). In the first step 5 children of class QObject and 5 children of class Derived are created for the application object. In the second step the children of class Derived shall be deleted. But instead all children are deleted, even the event dispatcher.

      Reason for that behaviour is, that QObject::findChildren uses the Qt's meta-object system and the kind, how the meta-object system works. Because this is somehow a time bomb (a Q_OBJECT macro could be removed accidently), QObject::findChildren should use 'dynamic_cast' instead.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            wschenke Winfried Schenke
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes