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

QML_SEQUENTIAL_CONTAINERS affects isArray and breaks ComboBox

    XMLWordPrintable

Details

    • 9088125f1 (dev), 1b89c1edc (dev), 71b4a5e6d (dev), 8d7facdce (6.5)

    Description

      The attached example feeds a simple QList<Entry>* model to a ComboBox and uses textRole to adjust the display text.

      QML:

      Window {
          Component.onCompleted: () => {
              let tmp = Foo.getEntries()
              console.log("Model is array: " + Array.isArray(tmp))
              selector.model = tmp
          }
      
          ComboBox {
              id: selector
              textRole: 'name'
          }
      } 

      List:

      class Entry : public QObject {
          Q_OBJECT
          Q_PROPERTY(QString name MEMBER m_name CONSTANT FINAL)
      
      public:
          explicit Entry(const QString& name, QObject* parent = nullptr) :
              QObject(parent), m_name(name) {}
      
      private:
          QString m_name;
      };
      
      class EntryWrapper {
          Q_GADGET
          QML_FOREIGN(Entry)
          QML_NAMED_ELEMENT(Entry)
          QML_UNCREATABLE("These are my Entry objects")
      };
      
      class EntryListRegistration
      {
          Q_GADGET
          QML_FOREIGN(QList<Entry*>)
          QML_ANONYMOUS
          QML_SEQUENTIAL_CONTAINER(Entry*)
      };
      
      class Foo : public QObject {
          Q_OBJECT
          QML_ELEMENT
          QML_SINGLETON
      
      public:
          explicit Foo(QObject* parent = nullptr) : QObject(parent) {
              for (int i = 0; i < 10; i++) {
                  m_entries.push_back(new Entry(QString("Item %1").arg(i), this));
              }
          }    Q_INVOKABLE QList<Entry*> getEntries() const { return m_entries; }
      
      private:
          QList<Entry*> m_entries;
      };
      

       
      The resulting ComboBox shows the selected entry, but when opening it, it shows invisible entries. This is because isArray is false for the model. Removing the list registration makes it work.

      Attachments

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              cajus Cajus Pollmeier
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: