I am trying to change the values of a two-dimensional QVector (QVector<QVector<QString>
). However when attempting it, I get the following error: passing 'const QString' as 'this' argument discards qualifiers [-fpermissive]
.
I first thought that the problem was in the way I was accessing the data in the QVector
. I therefore tried accessing it via operator []
. This gave me the following error: no match for 'operator=' (operand types are 'QVector<QString>' and 'QString')
. I also tried dereferencing the vector (*SecondList
), as I wasn't sure whether operator []
did it and got the following error: no match for 'operator*' (operand type is 'const QVector<QString>')
.
Here is the problematic code:
void Handler::changePassword(QString newPassword, int id)
{
QString nP = newPassword;
int i = 0;
bool loopBreaker = false;
while (!loopBreaker)
{
if (SecondList->at(i).at(2) == QString::number(id))
{//Changes the value for password in "secondlist"
SecondList->at(i).at(0) = nP; // ----> ERROR
loopBreaker = true;
saveList();
}
i++;
}
}
Here is the header file for Handler
class
class Handler : public QWidget
{
private:
QVector<QVector<QString>> *SecondList = new QVector<QVector<QString>>;
}
(code is ommitted for readability)
QVector at() returns a const T&, try using operator [] instead, which returns non-const &