#include#include int main() { QString str = "Hello, world!"; QHash hash; for (auto ch : str) { if (ch.isLetter()) { hash[ch]++; } } for (auto it = hash.constBegin(); it != hash.constEnd(); it++) { qDebug() << it.key() << ":" << it.value(); } return 0; }
#includeThis code creates a hash table that maps integers to pointers to Person objects. It inserts two persons into the hash table and retrieves one of them by its key. It then prints the full name of the Person object using its member function `fullName()`. The `Person` class needs to be defined separately in a header file. The QHash class is part of the Qt Core library.#include "person.h" int main() { QHash hash; Person* p1 = new Person("John", "Doe"); Person* p2 = new Person("Jane", "Doe"); hash.insert(1, p1); hash.insert(2, p2); Person* p = hash.value(1); qDebug() << p->fullName(); // prints "John Doe" delete p1; delete p2; return 0; }