From 67ef2583e481a37d51cb9d5d4d6046069559a754 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 1 Oct 2019 14:01:42 +0200 Subject: VDMAbstractItemModelDataType: ensure meta-type is initialized Since the delegate chooser can call value() on a delegate model before the first call to createItem(), we need to ensure that all structures (and in particular, m_rolenames) are populated also in this case. This is especially important for cases where value() is called for every item in the model, as is the case for e.g. auto-completion for combo boxes, as delegate creation is particularly expensive there. Task-number: QTBUG-78858 Change-Id: I66138d74839b9645d11c69c29f2e70264c65a68d Reviewed-by: Richard Moe Gustavsen --- src/qmlmodels/qqmladaptormodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp index 48ff4e7d5b..012540244f 100644 --- a/src/qmlmodels/qqmladaptormodel.cpp +++ b/src/qmlmodels/qqmladaptormodel.cpp @@ -459,6 +459,11 @@ public: QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override { + if (!metaObject) { + VDMAbstractItemModelDataType *dataType = const_cast(this); + dataType->initializeMetaType(model); + } + QHash::const_iterator it = roleNames.find(role.toUtf8()); if (it != roleNames.end()) { return model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex).data(*it); @@ -505,7 +510,7 @@ public: return new QQmlDMAbstractItemModelData(metaType, dataType, index, row, column); } - void initializeMetaType(QQmlAdaptorModel &model) + void initializeMetaType(const QQmlAdaptorModel &model) { QMetaObjectBuilder builder; setModelDataType(&builder, this); -- cgit v1.2.3