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
2
votes
3 answers

Is there a map-like tool in QT that can be iterated over inserted index?

From the Qt documentation about QMap::iterator : Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key (because they were inserted using QMap::insertMulti(), or due to…
euraad
  • 2,467
  • 5
  • 30
  • 51
2
votes
1 answer

QHash storing large amount of data

I've 10,000,000 entry of type struct{int, int, int, int}. when I store them using QHash or QMap, it occupies large amount of memory, indeed it must take about 10,000,000 * 4 * 4 (sizeof integer) <= 153 MB but when I load my data it takes about 1.2…
abdolahS
  • 663
  • 12
  • 35
2
votes
2 answers

Remove range of elements from QHash

I use QHash as a container and I have a task to remove all items that satisfy the predicate. At first I thought to use the Erase-remove idiom it turned out that QHash has no option to delete the range, but only a function to delete a single element…
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
2
votes
2 answers

How do you define a QHash with heterogeneous value types?

I need to have a QHash container that takes quint8 keys but takes heterogeneous types as values, all of which will be Qt containers or classes. As an example I might want to insert a QDate or QTime object or even quint8 as the value. How can I…
max
  • 2,627
  • 1
  • 24
  • 44
2
votes
1 answer

QMultiHash Iterator order for values of same key

Consider the following code: QMultiHash::iterator i = th.begin(); while(i != th.end()) { int key = i.key(); Value* val = i.value(); if(key == lastkey) { // Do something } else { // Do Something else …
Ameen
  • 1,857
  • 2
  • 23
  • 30
1
vote
2 answers

How to clean up a complex QList?

I'm using a rather complex QList in a derivation of QAbstractTableModel to store data: class MyTableModel : public QAbstractTableModel { Q_OBJECT QList *> *> m_data; …
WolfgangP
  • 3,195
  • 27
  • 37
1
vote
1 answer

How to make unique_ptr work with Qt's QHash and QString?

I am learning the intrincacies of unique_ptr. I have a working example of a std::unordered_map that holds std:string and std::unique_ptr. But I can't make unique_ptr examples with Qt's QString and QHash work. They won't compile…
Rsevero
  • 157
  • 2
  • 11
1
vote
1 answer

QSet append custom Object

I have the following class class Test{ int a; int b; }; and all that I want is to have a QSet where I will insert some Test objects. int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSet setTest; …
Mircea
  • 1,671
  • 7
  • 25
  • 41
1
vote
0 answers

How to implement qHash for QNetworkCookie

I'm trying to collect QNetworkCookies in a QSet. I create the QSet QSet cookies and then insert the cookies with cookies.insert(cookie); The compiler then tells me, that there is no qHash for QNetworkCookie, so I added an inline…
henrik
  • 708
  • 7
  • 14
1
vote
1 answer

Initializing const QHash by joining with an existing QHash

In my project I need several constant hash-containers which are defined outside classes and functions and so are global. With that, some of these containers should overlap. With lists I would do the following to combine second const list with the…
Maximko
  • 627
  • 8
  • 20
1
vote
3 answers

QSet does not compile by gcc

I'm trying to use QSet for storing a list of function pointers. See this code for more details. The problem is that this code does not compile by gcc/mingw. MSVC compiles it normally. What am I doing wrong? typedef intptr_t…
Sergey
  • 144
  • 1
  • 13
1
vote
2 answers

Partial key matching QHash

I have a QHash defined as follows QHash hashLookup; I have inserted a few values to this hash as follows: hashLookup.insert("OMG", "Oh my God!"); hashLookup.insert("LOL", "Laugh out loud"); hashLookup.insert("RIP", "Rest in…
smyslov
  • 1,279
  • 1
  • 8
  • 29
1
vote
1 answer

QHash of QPair iteration

QHash, QString name> info I have this QHash , and i have the values of N_id and name for a particular index, how can i obtain the value of corresponding A_id. I am trying to use STL-style iterator. I can change…
wazza
  • 313
  • 3
  • 19
1
vote
2 answers

Why doesn't Qt's qHash() have an overload for std::shared_ptr?

I just found out, to my surprise, that the following code does not compile out of the box in C++14 using Qt 5.4: QSet> var; The problem is that there is no overload of the qHash() method for std::shared_ptr, or any other…
Dimitar Asenov
  • 24,986
  • 1
  • 16
  • 20
1
vote
1 answer

Qt Delete Items from QMultiHash while Iterating

I want to delete items out of my QMultiHash. Looking at the docs, I believe I am doing it correctly but it always crashes after the first delete. What am I doing wrong? Here is my code: for (QMultiHash::iterator i =…
PhilBot
  • 748
  • 18
  • 85
  • 173