#include#include int main() { // Create a QMap with some key-value pairs QMap myMap; myMap.insert("Alice", 25); myMap.insert("Bob", 30); myMap.insert("Charlie", 35); // Get the size of the QMap int size = myMap.size(); // Print the size qDebug() << "Size of the QMap: " << size; return 0; }
#includeThis example creates a QStringList, then creates a QMap from the QStringList where the values are the length of the strings. Then, it gets the size of the QMap using the size() function, and prints it to the console. Package Library: Qt Library#include #include int main() { // Create a QStringList QStringList names; names << "Alice" << "Bob" << "Charlie"; // Create a QMap from the QStringList QMap myMap; for (QString name : names) { myMap.insert(name, name.length()); } // Get the size of the QMap int size = myMap.size(); // Print the size qDebug() << "Size of the QMap: " << size; return 0; }