C++可传递给QML的数据
一、传递QVariantList
注意:
typedef QList<QVariant> QVariantList
1、qml
function readValues(anArray, anObject) { for (var i = 0; i < anArray.length; i++ ) console.log("Array item:", anArray[ i ]) for (var prop in anObject) { console.log("Object item:", prop, "=", anObject[prop]) } }
2、C++
QVariantList listY; listY << 2 << 4 << 4.5 << 5 << 8 << 12 << 18; QMetaObject::invokeMethod(qw->rootObject(), "setValue",
Q_ARG(QVariant,QVariant::fromValue(listY)),
Q_ARG(QVariant,QVariant(info)));
总结:
//C++ QVariantList //QML var p = [1,2,3,4,5]
二、传递点的集合
1、QML传到C++
//QML var p = [Qt.point(1,1), Qt.point(2,2)] cppObject.updatePoint(p); //C++ class CppObject { void updatePoint(QVector<QPointf>& p) { //... } }
2、C++传到QML
QMetaObject::invokeMethod(qw->rootObject(), "setValue", Q_ARG(QVariant,QVariant::fromValue(listY)));
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html