我正在尝试更改二维 QVector ( QVector<QVector<QString>
) 的值。但是,在尝试时,出现以下错误:passing 'const QString' as 'this' argument discards qualifiers [-fpermissive]
.
我首先认为问题出在我访问 QVector
中的数据的方式上。 .因此,我尝试通过 operator []
访问它.这给了我以下错误:no match for 'operator=' (operand types are 'QVector<QString>' and 'QString')
.我还尝试取消引用 vector ( *SecondList
),因为我不确定是否 operator []
这样做并得到以下错误:no match for 'operator*' (operand type is 'const QVector<QString>')
.
这是有问题的代码:
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++;
}
}
这是 Handler
的头文件类
class Handler : public QWidget
{
private:
QVector<QVector<QString>> *SecondList = new QVector<QVector<QString>>;
}
(为了便于阅读,省略了代码)
最佳答案
QVector at()返回一个 const T&,尝试使用 operator []相反,它返回 non-const &
关于c++ - 尝试更改二维 vector 的值时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57295600/