Unsolved How to populate a ListModel without for loop
-
Hello everyone.
I'm working on a Qt/QML software for data visualization that is meant to be quasi-real time.
In the software I'm working on, I populate a ListModel object as follows:main.qml
Test_Data { id: surfaceData } // some code function populate_model(x,y,my_data) { for(var i=0; i<array_data.length; i++) surfaceData.model.append({"row": y[i], "col": x[i], "value": my_data[i]); }
Test_Data.qml
import QtQuick 2.5 Item { property bool isempty: true property alias model: dataModel ListModel { id: dataModel } }
mainwindow.cpp
QObject *obj = my_widget->rootObject(); QMetaObject::invokeMethod(obj,"populate_model", Q_ARG(QVariant, QVariant::fromValue(array_x)), Q_ARG(QVariant, QVariant::fromValue(array_y)), Q_ARG(QVariant, QVariant::fromValue(array_data)));
where my_widget is a QQuickWidget and array_x, array_y and array_data are std vectors.
In short, is pass three arrays to the QML function and populate the ListModel with that for loop.
The problem is that the arrays are generally very big (hundreds of thousands of elements) and populating such model list takes about one one second.Is it possible to avoid the for loop with the appends to make the populating process faster?
-
@Davide87 Perhaps,
you get the solution here: https://forum.qt.io/topic/91426/model-for-a-list-of-large-data-in-qml/8 -
Thank you for your answer Bernd. However that topic is not actually much of help for me :-(
However, I'm thinking about leaving the QML idea and try another way to solve my problem.
Thank you again :-) -
@Davide87 If you want better performance you need to use C++.
QAbstractListModel
could do the job I think. You can use this "smart models" http://gitlab.unique-conception.org/qt-qml-tricks/qt-qml-models if you don't want to implement your own model. -
Thank you daljit. I'll try it.