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

qmlls complains "QQuickItem was not found" when custom type that inherits from QQuickItem is used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.8
    • 6.8.0
    • QML: Tooling
    • None

    Description

      Given this very basic example:

      // customitem.h
      #pragma once
      
      #include <QObject>
      #include <QQuickItem>
      #include <QtQml>
      
      class CustomItem : public QQuickItem
      {
          Q_OBJECT
          QML_ELEMENT
      public:
          CustomItem();
      
      signals:
      };
      // Main.qml
      import QtQuick
      
      import com.mycompany.qmlcomponents
      
      Window {
          Item {}
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          CustomItem {}
      }

      And you configure your CMakeLists.txt like this:

      qt_add_qml_module(appjust_qml
          URI com.mycompany.qmlcomponents
          VERSION 1.0
          QML_FILES
              Main.qml
              SOURCES customitem.h customitem.cpp
      )

      You get warnings from qmlls:

      QQuickItem was not found. Did you add all imports and dependencies? [import]
      Type CustomItem is used but it is not resolved [unresolved-type]

      This makes no sense at all (Qt Creator even offers a convenient option to directly inherit from QQuickItem when creating new class). If you change it to instead inherit from QObject then the warning is gone.

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            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