Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.4.3, 6.5.0 RC
-
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
- resulted in
-
QTBUG-113465 QQmlJSCodeGenerator::argumentsList() disregards most type wrappings
-
- Closed
-
For Gerrit Dashboard: QTBUG-112291 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
469856,1 | wip: Treat sequences and list properties like arrays | dev | qt/qtdeclarative | Status: DEFERRED | -2 | 0 |
474262,4 | Controls: Remove remaining isArray() hacks and improve delegates | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
476527,3 | QML: Allow conversion from QV4::Sequence to different iterable | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
476528,3 | QmlCompiler: Re-allow conversion from QObject to QString | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
476808,3 | QML: Allow conversion from QV4::Sequence to different iterable | 6.5 | qt/qtdeclarative | Status: MERGED | +2 | 0 |