qhash

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

折月煮酒 提交于 2020-02-23 06:48:06
问题 I want to use a std::string as the key of a QHash : QHash<std::string, QString> 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(), key.length()), seed); } Everything compiles correctly using MSVC, but gcc generates the following error: error: no matching function for call to qHash(const std::__cxx11::basic_string<char>&) How should I resolve this isse? 回答1: Short answer Define

QHash storing large amount of data

爷,独闯天下 提交于 2019-12-24 00:45:58
问题 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 GB for both QHash and QMap, why this occurs and how can I optimize it for both speed and memory?(through any other data structure or some tricks to qmap and qhash) 回答1: You've said in the comment that you are using another four ints as key - these

Understanding what QHash does when key not found

风流意气都作罢 提交于 2019-12-12 18:39:13
问题 Note: You can find a minimal working example at the end of this post. I'm using Qt 5.7 . Let's say I have the following QHash : QHash<HashKey, HashValue> hm; with enum HashKey { K1, K2, K3, K4, K5 } and class HashValue { public: int x; HashValue(int x) { this->x = x; } } I have initialized the hash map like this: hm.insert(K1, HashValue((int)K1)); hm.insert(K2, HashValue((int)K2)); hm.insert(K3, HashValue((int)K3)); hm.insert(K4, HashValue((int)K4)); hm.insert(K5, HashValue((int)K5)); I have

qvariant as key in qhash

送分小仙女□ 提交于 2019-12-10 20:24:14
问题 I want to create a data structure with QVariants a keys. It looks like this: QHash<QPair<QVariant, QVariant>, SHAPES::Shape* > _shapes; Unfortunately there is "no matching function for call to ‘qHash(const QVariant&)’". So I defined my own implementation of qHash for QVariants: #pragma once #include <QVariant> #include <QHash> uint qHash( const QVariant & var ) { if ( !var.isValid() || var.isNull() ) //return -1; Q_ASSERT(0); switch ( var.type() ) { case QVariant::Int: return qHash( var.toInt

Implementing a QHash-like lookup with multiple keys

荒凉一梦 提交于 2019-12-07 11:58:45
问题 I'm trying to find the best way to implement a QHash-like lookup table that uses multiple keys to return one value. I have read that the Boost library has similar functionality, but I would like to avoid this if possible. An example of what I would like to do is as follows (obviously the following pseudo-code is not possible): //First key (int) - Engine cylinders //Second key (int) - Car weight //Value (int) - Top speed MyLookup<int, int, int> m_Lookup m_Lookup.insert(6, 1000, 210); m_Lookup

Implementing a QHash-like lookup with multiple keys

落爺英雄遲暮 提交于 2019-12-05 21:28:09
I'm trying to find the best way to implement a QHash-like lookup table that uses multiple keys to return one value. I have read that the Boost library has similar functionality, but I would like to avoid this if possible. An example of what I would like to do is as follows (obviously the following pseudo-code is not possible): //First key (int) - Engine cylinders //Second key (int) - Car weight //Value (int) - Top speed MyLookup<int, int, int> m_Lookup m_Lookup.insert(6, 1000, 210); m_Lookup.insert(6, 1500, 190); m_Lookup.value(6, 1000); //Returns 210 My first (and extremely slow) idea was to