#include#include int main() { QMap map; map.insert(1, "one"); map.insert(2, "two"); map.insert(3, "three"); int key = 2; if(map.contains(key)) { std::cout << "Key " << key << " found" << std::endl; } else { std::cout << "Key " << key << " not found" << std::endl; } return 0; }
#includeThis code creates a QMap object and inserts three key-value pairs. It then checks if the map contains the key "four" using the contains function. These code examples use the QMap container class provided by the Qt library.#include #include int main() { QMap map; map.insert("one", 1); map.insert("two", 2); map.insert("three", 3); QString key = "four"; if(map.contains(key)) { std::cout << "Key " << qPrintable(key) << " found" << std::endl; } else { std::cout << "Key " << qPrintable(key) << " not found" << std::endl; } return 0; }