Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
6.5.0 RC
-
None
Description
There seems to be no way (besides using var) to pass a list<string> to a QStringList, currently:
Window { property list<string> someList: ["foo", "bar"] Component.onCompleted: { Foo.names = someList; } }
and
class Foo : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON Q_PROPERTY(QStringList names READ names WRITE setNames NOTIFY namesChanged FINAL) public: explicit Foo(QObject* parent = nullptr) : QObject(parent) {} QStringList names() const { return m_names; } void setNames(const QStringList& list) { m_names = list; emit namesChanged(); } signals: void namesChanged(); private: QStringList m_names; };
renders into
Warning: Main.qml:14:21: Could not compile binding for onCompleted: cannot convert from QList<QString> of (component in /var/home/prcs1076/tmp/build-andyflick-Desktop_Qt_6_5_0_GCC_64bit-Debug/Main.qml)::someList with type QString to QStringList of Foo::names with type QStringList [compiler] Foo.names = someList; ^^^^^^^^
. Which is technically correct, of course. Using "var" says
Warning: Main.qml:11:28: Could not compile binding for someList: Cannot generate efficient code for storing an array in a non-sequence type [compiler] property var someList: ["foo", "bar"] ^
.
So changing the API is the only way to get rid of warnings.