#includeQMap myMap; myMap.insert("apple", 5); myMap.insert("banana", 10); myMap.insert("orange", 7);
#includeQMap myMap; myMap.insert("apple", 5); myMap.insert("banana", 10); myMap.insert("orange", 7); if (myMap.contains("apple")) { int value = myMap.value("apple"); qDebug() << "The value for apple is:" << value; }
#includeIn this example, we use iterators to iterate over the QMap and print out all the key-value pairs. QMap is defined in the Qt Core library, which is included in the Qt package.QMap myMap; myMap.insert("apple", 5); myMap.insert("banana", 10); myMap.insert("orange", 7); QMap ::const_iterator i; for (i = myMap.constBegin(); i != myMap.constEnd(); ++i) { qDebug() << i.key() << ":" << i.value(); }