QMap that don't work properly
Solved
General and Desktop
-
Hi, I've this code:
QMap<uint8_t, uint8_t> OTable; OTable.insert( 1, '0'); OTable.insert( 0, '1'); OTable.insert( 5, '2'); OTable.insert( 7, '3'); OTable.insert( 9, '4'); OTable.insert(13, '5'); OTable.insert(15, '6'); OTable.insert(17, '7'); OTable.insert(19, '8'); OTable.insert(21, '9'); OTable.insert( 1, 'A'); OTable.insert( 0, 'B'); OTable.insert( 5, 'C'); OTable.insert( 7, 'D'); OTable.insert( 9, 'E'); OTable.insert(13, 'F'); OTable.insert(15, 'G'); OTable.insert(17, 'H'); OTable.insert(19, 'I'); OTable.insert(21, 'J'); OTable.insert( 2, 'K'); OTable.insert( 4, 'L'); OTable.insert(18, 'M'); OTable.insert(20, 'N'); OTable.insert(11, 'O'); OTable.insert( 3, 'P'); OTable.insert( 6, 'Q'); OTable.insert( 8, 'R'); OTable.insert(12, 'S'); OTable.insert(14, 'T'); OTable.insert(16, 'U'); OTable.insert(10, 'V'); OTable.insert(22, 'W'); OTable.insert(25, 'X'); OTable.insert(24, 'Y'); OTable.insert(23, 'Z'); qDebug() << OTable.key('A'); //Returns 1 qDebug() << OTable.key('Z'); //Returns 23 qDebug() << OTable.key('X'); //Returns 25 qDebug() << OTable.key('0'); //Returns 0 qDebug() << OTable.key('3'); //Returns 0 qDebug() << OTable.key('9'); //Returns 0
I don't understand why if I ask a key value of A-Z it works fine, but if I ask of 0-9 it returns always zero.
I tried to pass ascii code directly, but the result is the same.
I'm a bit confused.
Do you have some ideas?
Thanks.Stefano
-
Hi
Dont you replace
OTable.insert( 1, '0');
with
OTable.insert( 1, 'A');
? (same key)
docs says
"If there are multiple items with the key key, the most recently inserted item's value is replaced with value." -
@Stefanoxjx said in QMap that don't work properly:
I'm a bit confused.
You have a map, not a multimap so
OTable.insert( 1, 'A');
overwrites
OTable.insert( 1, '0');
-
Many thanks for clarification.
I understand the problem :)Stefano