#include#include int main() { QHash hash{{"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}}; auto iter = hash.constBegin(); for (; iter != hash.constEnd(); ++iter) { qDebug() << iter.key() << " : " << iter.value(); } return 0; }
#includeIn this example, we create a QHash object named `hash` with some key-value pairs. We then iterate through each element of the QHash using the `constBegin()` method and retrieve the value of the key 'B' using the `iter.value()` method. This function belongs to the Qt library’s QMap and QHash package.#include int main() { QHash hash{{"A", "One"}, {"B", "Two"}, {"C", "Three"}}; for(auto iter = hash.constBegin(); iter != hash.constEnd(); ++iter) { if(iter.key() == "B") { qDebug() << "The value of key 'B' is: " << iter.value(); } } return 0; }