Hi, I want to modify the value in a QMap, but when I tried to modify it through QMap::value(), I failed, because this method always return a value which is const(cannot be changed).
Do you guys know how to change the value in QMap??
Thanks!
Printable View
Hi, I want to modify the value in a QMap, but when I tried to modify it through QMap::value(), I failed, because this method always return a value which is const(cannot be changed).
Do you guys know how to change the value in QMap??
Thanks!
You can modify the value using [] operator. Some like this
Code:
map["one"] = 1; map["three"] = 3; map["seven"] = 7;
Thanks, but if I am using QMap in this way, QMap<int, QMap<QString, QToolButton *> >, then how can I add QToolButton into the inner QMap??
Like this
Code:
map[1]["one"] = toolButton
I use this, but the application crashed:
Code:
QMap<QString, QToolButton *> *currentButtons = const_cast<QMap<QString, QToolButton *>*>(tabs.value(ui->tabWidget->currentIndex())); currentButtons->insert(path, btn); //This line is where the error lie
I am really puzzled.
Did I fail to const_cast the const into non-cosnt so that I cannot insert a value into a const variable??
There is an iterator for map.