#include#include int main() { QHash hash; hash.insert("One", 1); hash.insert("Two", 2); hash.insert("Three", 3); for (auto it = hash.begin(); it != hash.end(); ++it) { std::cout << it.key().toStdString() << ": " << it.value() << std::endl; } return 0; }
#includeIn this example, we create a QHash container and insert three key-value pairs. We use constBegin() function to obtain a const_iterator pointing to the first item in the container. We traverse the container using the const_iterator and print out the key-value pairs. The QHash container class is part of the Qt Core module.#include int main() { QHash hash; hash.insert("One", 1); hash.insert("Two", 2); hash.insert("Three", 3); for (QHash ::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it) { std::cout << it.key().toStdString() << ": " << it.value() << std::endl; } return 0; }