[Interest] QML Transparent conversion of QVariantList<QVariantList>> of ints

Jason H jhihn at gmx.com
Fri Nov 16 15:58:15 CET 2018


Creating list of list of ints requires insert:
QVariantList qlines;
std::vector<cv::Vec4i> lines;
...
for( size_t i = 0; i < lines.size(); i++ )
{
    qlines.insert(qlines.size(), QVariantList{ lines[i][0], lines[i][1], lines[i][2], lines[i][3]}); // lines = [[839, 619, 1118, 845], [763,550,1199,904]]
}
//(QVariant(QVariantList, (QVariant(int, 839), QVariant(int, 619), QVariant(int, 1118), QVariant(int, 845))), ...)

So far so good.
I then call setProperty("lines", qlines), and read it back in QML:

onLinesChanged: console.log("LINES:", lines)
//qml: LINES: [839,619,1118,845,763,550,1199,904, ...]
Expected:
//qml: LINES: [[839, 619, 1118, 845], [763,550,1199,904]]

It seems that whatever conversion code is happening, is using QList::append or << and not the insert line above? Or am I doing something wrong?



More information about the Interest mailing list