Hash Tables with QHash : QHash « Qt « C++






Hash Tables with QHash

  

#include <QHash>
#include <QHashIterator>
#include <QDebug>

int main()
{
  QHash<QString, int> hash;

  hash["one"] = 1; // insert using [] operator
  hash["two"] = 2;
  hash.insert("seven", 7); // insert using insert()

  qDebug() << hash["seven"]; // value using [] operator
  qDebug() << hash.value("seven"); // value using value()

  QHashIterator<QString, int> i(hash);
  while (i.hasNext()) {
    i.next();
    qDebug() << i.key() << ":" << i.value();
  }
  return 0;
}

   
    
  








Related examples in the same category

1.QHash for object to int
2.QHash for string to int