Hi,
I use "VXYModelMapper" and "QStandardItemModel" in plot chart. I use following code but append model to VXYModelMapper is very slow. QElapsedTimer shows the delay in the last line.
I consume 123045 milliseconds if I do it after showing the window, if I do it before it consumes 0 millisecond :O. Well, I need the user to select a chart from the list to display it. So the code runs after after showing the window.
version of Qt: Qt 5.11.2
VXYModelMapper {
model: myChartClass.newMyChartModel
series: lineSeries
xColumn: 0
yColumn: 1
}
{
newMyChartModel= model;
emit myChartModelChanged(model);
}
foreach(const QJsonValue & val, npcArray){
double xVal=val.toObject().value("x").toDouble();
double yVal=val.toObject().value("y").toDouble();
lineModel->setItem(i, 0, item1);
lineModel->setItem(i, 1, item2);
i+=1;
}
//To this line everything is very good and fast
QElapsedTimer timer;
timer.start();
myChartClass->setMyChartModel(lineModel);
qDebug() << "The slow operation took" << timer.elapsed() << "millisecond";
VXYModelMapper {
model: myChartClass.newMyChartModel
series: lineSeries
xColumn: 0
yColumn: 1
}
void MyChartClass::setMyChartModel(QStandardItemModel *model)
{
newMyChartModel= model;
emit myChartModelChanged(model);
}
QStandardItemModel* lineModel=new QStandardItemModel(npcArray.size(), 2);
foreach(const QJsonValue & val, npcArray){
double xVal=val.toObject().value("x").toDouble();
double yVal=val.toObject().value("y").toDouble();
QStandardItem *item1 = new QStandardItem(QString::number(xVal));
lineModel->setItem(i, 0, item1);
QStandardItem *item2 = new QStandardItem(QString::number(yVal));
lineModel->setItem(i, 1, item2);
i+=1;
}
//To this line everything is very good and fast
QElapsedTimer timer;
timer.start();
myChartClass->setMyChartModel(lineModel);
qDebug() << "The slow operation took" << timer.elapsed() << "millisecond";
To copy to clipboard, switch view to plain text mode
Output:
The slow operation took 123045 millisecond.
Total point count: 5188
The slow operation took 123045 millisecond.
Total point count: 5188
To copy to clipboard, switch view to plain text mode
It is very slow
Please guide me.
Bookmarks