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

QList<Pointer> not compilable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • 6.12
    • 6.4.1
    • QML: Compiler

       

      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()
                                   ^^^^^^^
      

       

        1. sandbox.tgz
          1 kB
          Cajus Pollmeier
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

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

              Created:
              Updated:

                There are no open Gerrit changes