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

can't find Text(using in QML) by ojbectName in qt6.5.1 in certain situations ,but it's fine in qt5.15.9

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.1
    • None
    • Linux/Wayland

    Description

      maby it's the function which names "qt_qFindChild_helper" changing causes that you can't find Text(using in QML) which is as the child of Node(QtQuick3D qml type) by the fucntion naming findChild(using in cpp)

      Qt5.15.9

      QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options)
      {
          if (!parent)
              return nullptr;
          const QObjectList &children = parent->children();
          QObject *obj;
          int i;
          for (i = 0; i < children.size(); ++i) {
              obj = children.at(i);
              if (mo.cast(obj) && (name.isNull() || obj->objectName() == name))
                  return obj;
          }
          if (options & Qt::FindChildrenRecursively) {
              for (i = 0; i < children.size(); ++i) {
                  obj = qt_qFindChild_helper(children.at(i), name, mo, options);
                  if (obj)
                      return obj;
              }
          }
          return nullptr;
      }
      

      qt6.5.1

      QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options)
      {
          Q_ASSERT(parent);
          for (QObject *obj : parent->children()) {
              if (mo.cast(obj) && (name.isNull() || obj->objectName() == name))
                  return obj;
          }
          if (options & Qt::FindChildrenRecursively) {
              for (QObject *child : parent->children()) {
                  if (QObject *obj = qt_qFindChild_helper(child, name, mo, options))
                      return obj;
              }
          }
          return nullptr;
      }
      
      

      if you want to access qml Text from cpp ,follow the example below:
      https://github.com/liurunjieDW/qt6_issue.git
      you can't find the Text in qt6.5.1,but you can find the Text in qt5.15.9

      Attachments

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

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            ninja ninja uk
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes