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

qmlls does not properly resolve the property type with unqualified type name in Q_PROPERTY

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.10
    • 6.7.3
    • None
    • Windows

    Description

      qmlls seemingly cannot resolve the property type if it's declared with unqualified name when the classes are in a namespace.

      Given the follow example:

       

      // MyView.h
      #pragma once
      #include <QQmlEngine>
      #include <QQuickItem>
      
      #include "MyModel.h"
      
      namespace Nested {
      
      class MyView : public QQuickItem
      {
          Q_OBJECT
          QML_ELEMENT
          Q_PROPERTY(MyModel * myModel READ myModel NOTIFY myModelChanged FINAL)
      
      public:
          inline MyView() : m_myModel(new Nested::MyModel{this}) {}
          inline Nested::MyModel *myModel() const { return m_myModel; }
      
      signals:
          void myModelChanged();
      
      private:
          Nested::MyModel *m_myModel;
      };
      
      }
      
      

       

      // MyModel.h
      #pragma once
      #include <QAbstractListModel>
      #include <QtQmlIntegration>
      
      namespace Nested {
      
      class MyModel : public QAbstractListModel
      {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          inline explicit MyModel(QObject *parent = nullptr)
              : QAbstractListModel(parent)
          {}
      
          inline int rowCount(const QModelIndex &parent = QModelIndex()) const override { return {}; }
          inline QVariant data(const QModelIndex &index, int role) const override { return {}; }
          inline QHash<int, QByteArray> roleNames() const override { return {}; }
      };
      
      }
      
      

       

      // Main.qml
      import QtQuick
      
      import qt_yet_another_bug
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          MyView {
              Text {
                  text: parent.myModel
              }
          }
      }
      
      

       

      # CMakeLists.txt
      qt_add_qml_module(appqt_yet_another_bug
          URI qt_yet_another_bug
          VERSION 1.0
          QML_FILES
              Main.qml
          SOURCES MyModel.h MyModel.cpp
          DEPENDENCIES QtQuick
          SOURCES MyView.h MyView.cpp
      )

      qmlls warns at the line text: parent.myModel:

      Type "MyModel" of property "myModel" not found. This is likely due to a missing dependency entry or a type not being exposed declaratively. [unresolved-type]

      The warning seems to be a false positive. There is no defect in runtime behavior.

      Currently, this can be worked-around by either moving both classes out of the Nested namespace, or by using fully qualified name in Q_PROPERTY:

      Q_PROPERTY(Nested::MyModel * myModel READ myModel NOTIFY myModelChanged FINAL)

       

      Attachments

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

        Activity

          People

            fabiankosmale Fabian Kosmale
            jclink Jessia Clinkscale
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes