QMapmyMap; // insert some elements to the map myMap.insert("a", 10); myMap.insert("b", 20); myMap.insert("c", 30); // Accessing the first element of map using begin() const QMap ::const_iterator iterator = myMap.begin(); QString firstKey = iterator.key(); // "a" int firstValue = iterator.value(); // 10
QMapIn this example, we have created a QMap named myMap and inserted some key-value pairs. We have used const_iterator to loop over all elements of the map and printed them using qDebug(). These examples are part of the Qt library, which is a cross-platform application framework.myMap; // insert some elements to the map myMap.insert("John", "Doe"); myMap.insert("Alice", "Smith"); myMap.insert("Bob", "Johnson"); // Printing all elements of the map using iterator QMap ::const_iterator iterator; for(iterator = myMap.begin(); iterator != myMap.end(); ++iterator) { qDebug() << iterator.key() << ":" << iterator.value(); }