Questions tagged [qhash]

QHash is a Qt template class that provides a hash-table-based dictionary

QHash provides very similar functionality to QMap. The differences are:

  • QHash provides faster lookups than QMap.
  • When iterating over a QMap, the items are always sorted by key. With QHash, the items are arbitrarily ordered.
  • The key type of a QMap must provide operator<(). The key type of a QHash must provide operator==() and a global hash function called qHash() (see qHash).

Documentation can be found here for Qt 4.8 and here for Qt 5.

68 questions
1
vote
0 answers

Nested QHash Not Saving

I have a function read (that takes and returns void), which stores data from a file into a QHash > -- for clarity, let's call any QHash fitting this template hash. My aim was to make a "master" list of all the hashes…
user3329769
  • 31
  • 1
  • 3
1
vote
2 answers

How to create three dimensional array with QHash?

I want to create QHash with three arguments: QHash myhash; I know that I have to use nested QHash, so I did: QHash > myhash; But I could not figure out how I can insert values to myhash. I tried…
amol01
  • 1,823
  • 4
  • 21
  • 35
1
vote
1 answer

Qt 5.1 qHash error

When I define a class to use hash,encounter some question.IDE show error: "error C2665: “qHash”: 17 overloads can not convert all parameter types D:\Qt\Qt5.1.1_x86\5.1.1\msvc2012\include\QtCore\qhash.h 111 1" I think exception code is overload…
user2492798
  • 589
  • 1
  • 4
  • 8
1
vote
3 answers

loop through nested QHash with foreach

I have QHash myNestedQHash; and when I try foreach (QHash stat, myNestedQHash.values(someStr)) I get error: macro "Q_FOREACH" passed 3 arguments, but takes just 2 Isn't it possible…
mrz
  • 1,802
  • 2
  • 21
  • 32
0
votes
2 answers

Creating a model for a data stored in a QHash

I have a QHash of items I want to display in a QTableView. So I need a model. The MyClass has an internal id, which is used to insert into the map. Something like this: // when adding a new item my_super_hash[item->id] = item; When implementing the…
elcuco
  • 8,948
  • 9
  • 47
  • 69
0
votes
1 answer

Insertion into QSet vs QHash

I would like to know how insert into QSet exactly works. Does QSet compare all items with the new item while inserting? Because if it does, i would use QHash with a simple ID as key instead of using QSet with a container class, which has more…
dce_54
  • 1
  • 1
0
votes
0 answers

Overriding qHash() using a hashing function without a seed

I'm trying to write an overload of qHash where the hash will be computed using a Core Foundation type. Apple provides the following function for this: CFHashCode CFHash(CFTypeRef cf); This is all well and good, but qHash requires a second argument,…
Bri Bri
  • 2,169
  • 3
  • 19
  • 44
0
votes
1 answer

Iterating over a QHash VS std::unordered_map

#include #include #include #include #include #include void _QMap() { QMap amap; amap.insert(2, "cdasdc"); amap.insert(1, "cda"); amap.insert(3, "zzz"); …
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
0
votes
1 answer

Is QMap a hash table?

I used Qmap many times but perhaps never used QHash. Now I'm reading about hash tables. Is QMap a hash table? I presume down there in a QHash we will find the ideas of Hash Maps. Should I say QHash is the implementation of a hash map (or hash table)…
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
0
votes
1 answer

How to use QHash::removeIf(Predicate Pred)

Qt 6.1 introduced the method removeIf(Predicate Pred) to a number of its collection classes: QByteArray, QHash, QList, QMap, QMultiHash, QMultiMap, QString and QVarLengthArray. But how do I write a predicate? Let's take a QHash example: struct…
Paul Masri-Stone
  • 2,843
  • 3
  • 29
  • 51
0
votes
2 answers

QHash behaving different in different qt version

I am compiling below code in QT version 4.8 as well as in 5.12.9 . QHash m_userDataHash; m_userDataHash.insert("white", 1); m_userDataHash.insert("yellow", 3); m_userDataHash.insert("lightblue", 5); m_userDataHash.insert("darkblue",…
kernel
  • 326
  • 1
  • 3
  • 18
0
votes
1 answer

How to use std::string as key of QHash?

I want to use a std::string as the key of a QHash: QHash m_hash; m_hash.insert("ABC", "DEF"); I implemented the required qHash: inline qHash(const std::string& key, uint seed = 0) { qHash(QByteArray::fromRawData(key.data(),…
m7913d
  • 10,244
  • 7
  • 28
  • 56
0
votes
0 answers

VS 2017 Error C2665 'qHash': none of the 30 overloads could convert all the argument types

I use QHash for a small program. CompleterData.h #include #include #include #include #include class CompleterData { public: enum class Type { Header, SecondHeader, Data, …
gnase
  • 580
  • 2
  • 10
  • 25
0
votes
0 answers

C++ Inheritance QHash different key type

I am currently working on a project where I have a situation I am trying to solve. I have a base class that has a QHash that stores some objects. Currently I have two derived classes. The problem is that for one derived class I would like the key to…
thecaptain0220
  • 2,098
  • 5
  • 30
  • 51