Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.15
-
d621027babff9a30d56ab6af871a465108c9eaba
Description
https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#sequence-type-to-javascript-array says that QVector<QString> can be converted to a JavaScript array. QTBUG-67459 was closed as a duplicate of QTBUG-60134, which was supposedly fixed by https://codereview.qt-project.org/c/qt/qtdeclarative/+/191873. However, this example shows that the Repeater's count is 0 when such a model is assigned (despite printing the array showing that there is one item):
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QAbstractListModel> #include <QQmlContext> #include <QKeyEvent> #include <QDebug> #include <QAbstractListModel> class ItemData : public QObject { Q_OBJECT Q_PROPERTY(QVector<QString> roundNames READ roundNamesVector CONSTANT FINAL) public: ItemData(QObject *parent = nullptr) : QObject(parent) {} QVector<QString> roundNamesVector() const { return QVector<QString>(mRoundNames.constBegin(), mRoundNames.constEnd()); } QSet<QString> mRoundNames; }; int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; qmlRegisterAnonymousType<ItemData>("App", 1); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); ItemData itemData; itemData.mRoundNames.insert(QLatin1String("Test")); engine.rootObjects().first()->setProperty("itemData", QVariant::fromValue(&itemData)); return app.exec(); } #include "main.moc"
main.qml
import QtQuick 2.14 import QtQuick.Window 2.14 Window { id: root width: 300 height: 480 title: "count: " + repeater.count + " roundNames: " + (itemData ? itemData.roundNames : []) visible: true property var itemData Flow { anchors.fill: parent Repeater { id: repeater model: root.itemData ? root.itemData.roundNames : null delegate: Text { text: modelData } } } }
Attachments
Issue Links
- relates to
-
QTBUG-67459 Assigning QVector<QString> to Repeater's model property doesn't work
- Closed