View Full Version : QMap
sophister
5th May 2009, 10:21
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
map["one"] = 1;
map["three"] = 3;
map["seven"] = 7;
sophister
5th May 2009, 10:36
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
map[1]["one"] = toolButton
sophister
5th May 2009, 10:59
I use this, but the application crashed:
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??
lyuts
25th May 2009, 11:05
There is an iterator for map.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.