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!
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
Qt Code:
map["one"] = 1; map["three"] = 3; map["seven"] = 7;To copy to clipboard, switch view to plain text mode
Mithin
www.mithin.in
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
Qt Code:
map[1]["one"] = toolButtonTo copy to clipboard, switch view to plain text mode
Mithin
www.mithin.in
I use this, but the application crashed:
Qt 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 lieTo copy to clipboard, switch view to plain text mode
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.
I'm a rebel in the S.D.G.
Bookmarks