Discussion:
QML Transparent conversion of QVariantList<QVariantList>> of ints
(too old to reply)
Jason H
2018-11-16 14:58:15 UTC
Permalink
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?
Jason H
2018-11-16 15:54:51 UTC
Permalink
Update: It seems that it's stored correctly, just not printed correctly.
That is to say: lines[0] = [839, 619, 1118, 845], as expected.
Sent: Friday, November 16, 2018 at 9:58 AM
Subject: [Interest] QML Transparent conversion of QVariantList<QVariantList>> of ints
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.
onLinesChanged: console.log("LINES:", lines)
//qml: LINES: [839,619,1118,845,763,550,1199,904, ...]
//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?
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Continue reading on narkive:
Loading...