QMapmyMap; if (myMap.isEmpty()) { qDebug() << "The map is empty"; }
QMapIn this example, we create a QMap called myMap and populate it with two key-value pairs using the insert() function. We then use the isEmpty() function to check if it is empty. Since it is not empty, the message "The map contains 2 elements" will be printed to the console. The QMap class is part of the Qt Core module, which is included in the Qt library.myMap; myMap.insert("John", 42); myMap.insert("Mary", 35); if (myMap.isEmpty()) { qDebug() << "The map is empty"; } else { qDebug() << "The map contains" << myMap.count() << "elements"; }