I have a struct like this one :
struct Nom {
QString Nom;
....
QList<quint64> indNum;
}
In my .h file. I declare :
QVector *n;
In my .cpp file. I declare :
n = new QVector<Nom>;
I read a file to fill in n. When I write this :
n->back().indNum.append(i->size()-1);
it works.
When I write that :
n->at(j).indNum.append(i->size()-1);
I have a compilation error:
no matching member funtion for call to 'append'
candidate function not viable: 'this' argument has type 'const QList', but method is not marked const void append(const T &t);
I don't understand why it works in the first case and the second. Could anyone explain and help me solve this ? Thanks in advance.
QVector::at
returns a const reference to theNom
value, so you cannot modify the item returned byn->at(j)
. To get a non-const reference you can use(*n)[j]
.n->back()
works because forQVector::back
there is a const and a non-const overload.