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

QList<Pointer> not compilable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.10
    • 6.4.1
    • QML: Compiler

    Description

       

      Using a list of Foobar pointers defined like

      class Foobar : public QObject {
          Q_OBJECT
          QML_ELEMENT
          QML_UNCREATABLE("Read only")
          Q_DISABLE_COPY(Foobar)
      
      public:
          Foobar(QObject* parent = nullptr) : QObject(parent) {}
          Q_INVOKABLE int baz() const { return 42; }
      };
      
      class Druggeljug : public QObject {
          Q_OBJECT
          QML_ELEMENT
          QML_SINGLETON
      
      public:
          Druggeljug(QObject* parent = nullptr) : QObject(parent) {
              for (int i = 0; i < 5; ++i) {
                  m_foos.append(new Foobar(this));
              }
          }
      
          Q_INVOKABLE QList<Foobar*> getList() const { return m_foos; }
      
      private:
          QList<Foobar*> m_foos;
      };
      

      used in

      function showList() {
              const l = Druggeljug.getList()
              for (const foo of l) {
                  console.log(foo.baz())
              }
          }
      

      works at runtime, but cannot be compiled:

      Warning: main.qml:12:30: Could not compile function showList: return type QList<Foobar*> cannot be resolved [compiler]
              const l = Druggeljug.getList()
                                   ^^^^^^^
      

       

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              cajus Cajus Pollmeier
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes