N
N
Nikita Presnov2021-07-19 16:33:08
Qt
Nikita Presnov, 2021-07-19 16:33:08

How to work with QList correctly?

We have a classic template program in Qt5, that is, there are files main.cpp, name.h, name.cpp.
In the file name.h there is a class app from qmainwindow, in it

private:
    ...
    QList<QwtPlotCurve> *graph;


The class constructor has

graph = new QList<QwtPlotCurve>[10];
for(int i=0; i < graph->size(); i++)
{

}


QwtPlotCurve has its own methods, and I need to recolor each curve in its own color, attach them to the widget via attach, and then update with a period of 1/25 sec. Separately with the curve, when they are not members of QList, I know how to work, but there's a gag. For example , they

graph[i].attach(ui->graphWidget);

swear No member named 'attach' in 'QList<QwtPlotCurve>', although QwtPlotCurve has such a method.

graph->at(i).attach(m_ui->graphWidget);

spits out
'this' argument to member function 'attach' has type 'const QwtPlotCurve', but function is not marked const
.

What is the correct way to access QList elements?

PS. I know how to read the exhaust, where my legs grow from, I understand, I don’t understand what to do.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2021-07-19
@discipuli

It is possible like this:

private: 
QList<QwtPlotCurve> graph;

for(int i=0; i < 10; i++)
{
QwtPlotCurve curve;
carve.attach(…);
graph.push_back(curve);
}

A
Armenian Radio, 2021-07-19
@gbg

You've new QList<QwtPlotCurve>[10];created an array of 10 lists here. Are you sure this is what you wanted?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question