Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QHash< Key, T > Class Template Reference

\inmodule QtCore More...

#include <qhash.h>

+ Collaboration diagram for QHash< Key, T >:

Classes

class  const_iterator
 \inmodule QtCore More...
 
class  iterator
 \inmodule QtCore More...
 
class  key_iterator
 \inmodule QtCore More...
 

Public Types

using key_type = Key
 Typedef for Key.
 
using mapped_type = T
 Typedef for T.
 
using value_type = T
 
using size_type = qsizetype
 Typedef for int.
 
using difference_type = qsizetype
 Typedef for ptrdiff_t.
 
using reference = T &
 
using const_reference = const T &
 
typedef QKeyValueIterator< const Key &, const T &, const_iteratorconst_key_value_iterator
 \inmodule QtCore
 
typedef QKeyValueIterator< const Key &, T &, iteratorkey_value_iterator
 \inmodule QtCore
 
typedef iterator Iterator
 Qt-style synonym for QHash::iterator.
 
typedef const_iterator ConstIterator
 Qt-style synonym for QHash::const_iterator.
 

Public Member Functions

 QHash () noexcept=default
 Constructs an empty hash.
 
 QHash (std::initializer_list< std::pair< Key, T > > list)
 
 QHash (const QHash &other) noexcept
 Constructs a copy of other.
 
 ~QHash ()
 Destroys the hash.
 
QHashoperator= (const QHash &other) noexcept(std::is_nothrow_destructible< Node >::value)
 Assigns other to this hash and returns a reference to this hash.
 
 QHash (QHash &&other) noexcept
 Move-constructs a QHash instance, making it point at the same object that other was pointing to.
 
template<typename InputIterator , QtPrivate::IfAssociativeIteratorHasKeyAndValue< InputIterator > = true>
 QHash (InputIterator f, InputIterator l)
 
template<typename InputIterator , QtPrivate::IfAssociativeIteratorHasFirstAndSecond< InputIterator > = true>
 QHash (InputIterator f, InputIterator l)
 
void swap (QHash &other) noexcept
 
template<typename Predicate >
qsizetype removeIf (Predicate pred)
 
take (const Key &key)
 Removes the item with the key from the hash and returns the value associated with it.
 
bool contains (const Key &key) const noexcept
 Returns true if the hash contains an item with the key; otherwise returns false.
 
qsizetype count (const Key &key) const noexcept
 Returns the number of items associated with the key.
 
Key key (const T &value) const noexcept
 
Key key (const T &value, const Key &defaultKey) const noexcept
 
value (const Key &key) const noexcept
 
value (const Key &key, const T &defaultValue) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the value associated with the key.
 
T & operator[] (const Key &key)
 Returns the value associated with the key as a modifiable reference.
 
const T operator[] (const Key &key) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as value().
 
QList< Keykeys () const
 Returns a list containing all the keys in the hash, in an arbitrary order.
 
QList< Keykeys (const T &value) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list containing all the keys associated with value value, in an arbitrary order.
 
QList< T > values () const
 Returns a list containing all the values in the hash, in an arbitrary order.
 
iterator begin ()
 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
 
const_iterator begin () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const_iterator cbegin () const noexcept
 
const_iterator constBegin () const noexcept
 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
 
iterator end () noexcept
 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the hash.
 
const_iterator end () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const_iterator cend () const noexcept
 
const_iterator constEnd () const noexcept
 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the hash.
 
key_iterator keyBegin () const noexcept
 
key_iterator keyEnd () const noexcept
 
key_value_iterator keyValueBegin ()
 
key_value_iterator keyValueEnd ()
 
const_key_value_iterator keyValueBegin () const noexcept
 
const_key_value_iterator constKeyValueBegin () const noexcept
 
const_key_value_iterator keyValueEnd () const noexcept
 
const_key_value_iterator constKeyValueEnd () const noexcept
 
auto asKeyValueRange () &
 
auto asKeyValueRange () const &
 
auto asKeyValueRange () &&
 
auto asKeyValueRange () const &&
 
iterator erase (const_iterator it)
 
std::pair< iterator, iteratorequal_range (const Key &key)
 
std::pair< const_iterator, const_iteratorequal_range (const Key &key) const noexcept
 
qsizetype count () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as size().
 
iterator find (const Key &key)
 Returns an iterator pointing to the item with the key in the hash.
 
const_iterator find (const Key &key) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const_iterator constFind (const Key &key) const noexcept
 
iterator insert (const Key &key, const T &value)
 Inserts a new item with the key and a value of value.
 
void insert (const QHash &hash)
 
template<typename ... Args>
iterator emplace (const Key &key, Args &&... args)
 
template<typename ... Args>
iterator emplace (Key &&key, Args &&... args)
 Inserts a new element into the container.
 
float load_factor () const noexcept
 Returns the current load factor of the QHash's internal hash table.
 
size_t bucket_count () const noexcept
 
bool empty () const noexcept
 This function is provided for STL compatibility.
 
template<typename K , if_heterogeneously_searchable< K > = true>
bool remove (const K &key)
 
template<typename K , if_heterogeneously_searchable< K > = true>
take (const K &key)
 
template<typename K , if_heterogeneously_searchable< K > = true>
bool contains (const K &key) const
 
template<typename K , if_heterogeneously_searchable< K > = true>
qsizetype count (const K &key) const
 
template<typename K , if_heterogeneously_searchable< K > = true>
value (const K &key) const noexcept
 
template<typename K , if_heterogeneously_searchable< K > = true>
value (const K &key, const T &defaultValue) const noexcept
 
template<typename K , if_heterogeneously_searchable< K > = true, if_key_constructible_from< K > = true>
T & operator[] (const K &key)
 
template<typename K , if_heterogeneously_searchable< K > = true>
const T operator[] (const K &key) const noexcept
 
template<typename K , if_heterogeneously_searchable< K > = true>
std::pair< iterator, iteratorequal_range (const K &key)
 
template<typename K , if_heterogeneously_searchable< K > = true>
std::pair< const_iterator, const_iteratorequal_range (const K &key) const noexcept
 
template<typename K , if_heterogeneously_searchable< K > = true>
iterator find (const K &key)
 
template<typename K , if_heterogeneously_searchable< K > = true>
const_iterator find (const K &key) const noexcept
 
template<typename K , if_heterogeneously_searchable< K > = true>
const_iterator constFind (const K &key) const noexcept
 

Static Public Member Functions

static float max_load_factor () noexcept
 
static size_t max_bucket_count () noexcept
 

Friends

class QSet< Key >
 
class QMultiHash< Key, T >
 
class iterator
 
class const_iterator
 
template<typename AKey = Key, typename AT = T, QTypeTraits::compare_eq_result_container< QHash, AKey, AT > = true>
bool comparesEqual (const QHash &lhs, const QHash &rhs) noexcept
 

Related Symbols

(Note that these are not member symbols.)

size_t qHash (const QUrl &url, size_t seed) noexcept
 Returns the hash value for the url.
 
size_t qHash (const QDateTime &key, size_t seed=0)
 
size_t qHash (QDate key, size_t seed=0)
 
size_t qHash (QTime key, size_t seed=0)
 
template< typename T1, typename T2 > size_t qHash (const std::pair< T1, T2 > &key, size_t seed=0)
 
template< typename... T > size_t qHashMulti (size_t seed, const T &...args)
 
template< typename... T > size_t qHashMultiCommutative (size_t seed, const T &...args)
 
template< typename InputIterator > size_t qHashRange (InputIterator first, InputIterator last, size_t seed=0)
 
template< typename InputIterator > size_t qHashRangeCommutative (InputIterator first, InputIterator last, size_t seed=0)
 
size_t qHashBits (const void *p, size_t len, size_t seed=0)
 
template< typname T, std::enable_if_t< std::is_same_v< T, bool >, bool >=true > size_t qHash (T key, size_t seed)
 
size_t qHash (char key, size_t seed=0)
 
size_t qHash (uchar key, size_t seed=0)
 
size_t qHash (signed char key, size_t seed=0)
 
size_t qHash (ushort key, size_t seed=0)
 
size_t qHash (short key, size_t seed=0)
 
size_t qHash (uint key, size_t seed=0)
 
size_t qHash (int key, size_t seed=0)
 
size_t qHash (ulong key, size_t seed=0)
 
size_t qHash (long key, size_t seed=0)
 
size_t qHash (quint64 key, size_t seed=0)
 
size_t qHash (qint64 key, size_t seed=0)
 
size_t qHash (quint128 key, size_t seed=0)
 
size_t qHash (qint128 key, size_t seed=0)
 
size_t qHash (char8_t key, size_t seed=0)
 
size_t qHash (char16_t key, size_t seed=0)
 
size_t qHash (char32_t key, size_t seed=0)
 
size_t qHash (wchar_t key, size_t seed=0)
 
size_t qHash (float key, size_t seed=0) noexcept
 
size_t qHash (double key, size_t seed) noexcept
 
size_t qHash (long double key, size_t seed) noexcept
 
size_t qHash (const QChar key, size_t seed=0)
 
size_t qHash (const QByteArray &key, size_t seed=0)
 
size_t qHash (const QByteArrayView &key, size_t seed=0)
 
size_t qHash (const QBitArray &key, size_t seed=0)
 
size_t qHash (const QString &key, size_t seed=0)
 
size_t qHash (QLatin1StringView key, size_t seed=0)
 
template< class T > size_t qHash (const T *key, size_t seed=0)
 
size_t qHash (std::nullptr_t key, size_t seed=0)
 
template< typename T > bool qHashEquals (const T &a, const T &b)
 
template< class Key, class T > QDataStreamoperator<< (QDataStream &out, const QHash< Key, T > &hash)
 Writes the hash hash to stream out.
 
template< class Key, class T > QDataStreamoperator>> (QDataStream &in, QHash< Key, T > &hash)
 Reads a hash from stream in into hash.
 
template< class Key, class T > size_t qHash (const QHash< Key, T > &key, size_t seed=0)
 
template< typename Key, typename T, typename Predicate > qsizetype erase_if (QHash< Key, T > &hash, Predicate pred)
 
size_t qHash (QPoint key, size_t seed=0)
 
size_t qHash (const QTypeRevision &key, size_t seed)
 
size_t qHash (const QVersionNumber &key, size_t seed)
 
size_t qHash (const QOcspResponse &response, size_t seed) noexcept
 Returns the hash value for the response, using seed to seed the calculation.
 
size_t qHash (const QSslCertificate &key, size_t seed) noexcept
 Returns the hash value for the key, using seed to seed the calculation.
 
size_t qHash (QSslEllipticCurve curve, size_t seed=0)
 
size_t qHash (const QSslError &key, size_t seed) noexcept
 Returns the hash value for the key, using seed to seed the calculation.
 
size_t qHash (const QGeoCoordinate &coordinate, size_t seed=0)
 Returns a hash value for coordinate, using seed to seed the calculation.
 

Detailed Description

template<typename Key, typename T>
class QHash< Key, T >

\inmodule QtCore

The QHash class is a template class that provides a hash-table-based dictionary. \compares equality

\reentrant

QHash<Key, T> is one of Qt's generic \l{container classes}. It stores (key, value) pairs and provides very fast lookup of the value associated with a key.

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

\list

  • QHash provides faster lookups than QMap. (See \l{Algorithmic Complexity} for details.)
  • 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 \l{qHash}). \endlist

Here's an example QHash with QString keys and int values:

To insert a (key, value) pair into the hash, you can use operator[]():

hash["one"] = 1;
hash["three"] = 3;
hash["seven"] = 7;

This inserts the following three (key, value) pairs into the QHash: ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the hash is to use insert():

hash.insert("twelve", 12);

To look up a value, use operator[]() or value():

int num1 = hash["thirteen"];
int num2 = hash.value("thirteen");

If there is no item with the specified key in the hash, these functions return a \l{default-constructed value}.

If you want to check whether the hash contains a particular key, use contains():

int timeout = 30;
if (hash.contains("TIMEOUT"))
timeout = hash.value("TIMEOUT");

There is also a value() overload that uses its second argument as a default value if there is no item with the specified key:

int timeout = hash.value("TIMEOUT", 30);

In general, we recommend that you use contains() and value() rather than operator[]() for looking up a key in a hash. The reason is that operator[]() silently inserts an item into the hash if no item exists with the same key (unless the hash is const). For example, the following code snippet will create 1000 items in memory:

// WRONG
...
for (int i = 0; i < 1000; ++i) {
if (hash[i] == okButton)
cout << "Found button at index " << i << endl;
}

To avoid this problem, replace hash[i] with hash.value(i) in the code above.

Internally, QHash uses a hash table to perform lookups. This hash table automatically grows to provide fast lookups without wasting too much memory. You can still control the size of the hash table by calling reserve() if you already know approximately how many items the QHash will contain, but this isn't necessary to obtain good performance. You can also call capacity() to retrieve the hash table's size.

QHash will not shrink automatically if items are removed from the table. To minimize the memory used by the hash, call squeeze().

If you want to navigate through all the (key, value) pairs stored in a QHash, you can use an iterator. QHash provides both \l{Java-style iterators} (QHashIterator and QMutableHashIterator) and \l{STL-style iterators} (QHash::const_iterator and QHash::iterator). Here's how to iterate over a QHash<QString, int> using a Java-style iterator:

QHashIterator<QString, int> i(hash);
while (i.hasNext()) {
i.next();
cout << qPrintable(i.key()) << ": " << i.value() << endl;
}

Here's the same code, but using an STL-style iterator:

for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
cout << qPrintable(i.key()) << ": " << i.value() << endl;

QHash is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap.

A QHash allows only one value per key. If you call insert() with a key that already exists in the QHash, the previous value is erased. For example:

hash.insert("plenty", 100);
hash.insert("plenty", 2000);
// hash.value("plenty") == 2000

If you need to store multiple entries for the same key in the hash table, use \l{QMultiHash}.

If you only need to extract the values from a hash (not the keys), you can also use range-based for:

...
for (int value : std::as_const(hash))
cout << value << endl;

Items can be removed from the hash in several ways. One way is to call remove(); this will remove any item with the given key. Another way is to use QMutableHashIterator::remove(). In addition, you can clear the entire hash using clear().

QHash's key and value data types must be \l{assignable data types}. You cannot, for example, store a QWidget as a value; instead, store a QWidget *.

\target qHash

Definition at line 820 of file qhash.h.

Member Typedef Documentation

◆ const_key_value_iterator

template<typename Key , typename T >
QKeyValueIterator<const Key&, const T&, const_iterator> QHash< Key, T >::const_key_value_iterator

\inmodule QtCore

Since
5.10

The QHash::const_key_value_iterator typedef provides an STL-style const iterator for QHash.

QHash::const_key_value_iterator is essentially the same as QHash::const_iterator with the difference that operator*() returns a key/value pair instead of a value.

See also
QKeyValueIterator

Definition at line 1233 of file qhash.h.

◆ const_reference

template<typename Key , typename T >
using QHash< Key, T >::const_reference = const T &

Definition at line 837 of file qhash.h.

◆ ConstIterator

template<typename Key , typename T >
const_iterator QHash< Key, T >::ConstIterator

Qt-style synonym for QHash::const_iterator.

Definition at line 1314 of file qhash.h.

◆ difference_type

template<typename Key , typename T >
using QHash< Key, T >::difference_type = qsizetype

Typedef for ptrdiff_t.

Provided for STL compatibility.

Definition at line 835 of file qhash.h.

◆ Iterator

template<typename Key , typename T >
iterator QHash< Key, T >::Iterator

Qt-style synonym for QHash::iterator.

Definition at line 1313 of file qhash.h.

◆ key_type

template<typename Key , typename T >
using QHash< Key, T >::key_type = Key

Typedef for Key.

Provided for STL compatibility.

Definition at line 831 of file qhash.h.

◆ key_value_iterator

template<typename Key , typename T >
QKeyValueIterator<const Key&, T&, iterator> QHash< Key, T >::key_value_iterator

\inmodule QtCore

Since
5.10

The QHash::key_value_iterator typedef provides an STL-style iterator for QHash.

QHash::key_value_iterator is essentially the same as QHash::iterator with the difference that operator*() returns a key/value pair instead of a value.

See also
QKeyValueIterator

Definition at line 1234 of file qhash.h.

◆ mapped_type

template<typename Key , typename T >
using QHash< Key, T >::mapped_type = T

Typedef for T.

Provided for STL compatibility.

Definition at line 832 of file qhash.h.

◆ reference

template<typename Key , typename T >
using QHash< Key, T >::reference = T &

Definition at line 836 of file qhash.h.

◆ size_type

template<typename Key , typename T >
using QHash< Key, T >::size_type = qsizetype

Typedef for int.

Provided for STL compatibility.

Definition at line 834 of file qhash.h.

◆ value_type

template<typename Key , typename T >
using QHash< Key, T >::value_type = T

Definition at line 833 of file qhash.h.

Constructor & Destructor Documentation

◆ QHash() [1/6]

template<typename Key , typename T >
QHash< Key, T >::QHash ( )
inlinedefaultnoexcept

Constructs an empty hash.

See also
clear()

◆ QHash() [2/6]

template<typename Key , typename T >
QHash< Key, T >::QHash ( std::initializer_list< std::pair< Key, T > > list)
inline
Since
5.1

Constructs a hash with a copy of each of the elements in the initializer list list.

Definition at line 840 of file qhash.h.

References QHash< Key, T >::insert().

+ Here is the call graph for this function:

◆ QHash() [3/6]

template<typename Key , typename T >
QHash< Key, T >::QHash ( const QHash< Key, T > & other)
inlinenoexcept

Constructs a copy of other.

This operation occurs in \l{constant time}, because QHash is \l{implicitly shared}. This makes returning a QHash from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes \l{linear time}.

See also
operator=()

Definition at line 846 of file qhash.h.

◆ ~QHash()

template<typename Key , typename T >
QHash< Key, T >::~QHash ( )
inline

Destroys the hash.

References to the values in the hash and all iterators of this hash become invalid.

Definition at line 852 of file qhash.h.

◆ QHash() [4/6]

template<typename Key , typename T >
QHash< Key, T >::QHash ( QHash< Key, T > && other)
inlinenoexcept

Move-constructs a QHash instance, making it point at the same object that other was pointing to.

Since
5.2

Definition at line 874 of file qhash.h.

References QHash< Key, T >::QHash().

Referenced by QHash< Key, T >::QHash().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QHash() [5/6]

template<typename Key , typename T >
template<typename InputIterator , QtPrivate::IfAssociativeIteratorHasKeyAndValue< InputIterator > = true>
QHash< Key, T >::QHash ( InputIterator begin,
InputIterator end )
inline
Since
5.14

Constructs a hash with a copy of each of the elements in the iterator range [begin, end). Either the elements iterated by the range must be objects with {first} and {second} data members (like {std::pair}), convertible to Key and to T respectively; or the iterators must have {key()} and {value()} member functions, returning a key convertible to Key and a value convertible to T respectively.

Definition at line 884 of file qhash.h.

◆ QHash() [6/6]

template<typename Key , typename T >
template<typename InputIterator , QtPrivate::IfAssociativeIteratorHasFirstAndSecond< InputIterator > = true>
QHash< Key, T >::QHash ( InputIterator f,
InputIterator l )
inline

Definition at line 893 of file qhash.h.

Member Function Documentation

◆ asKeyValueRange() [1/4]

template<typename Key , typename T >
auto QHash< Key, T >::asKeyValueRange ( ) &
inline

Definition at line 1253 of file qhash.h.

◆ asKeyValueRange() [2/4]

template<typename Key , typename T >
auto QHash< Key, T >::asKeyValueRange ( ) &&
inline

Definition at line 1255 of file qhash.h.

◆ asKeyValueRange() [3/4]

template<typename Key , typename T >
auto QHash< Key, T >::asKeyValueRange ( ) const &
inline

Definition at line 1254 of file qhash.h.

◆ asKeyValueRange() [4/4]

template<typename Key , typename T >
auto QHash< Key, T >::asKeyValueRange ( ) const &&
inline

Definition at line 1256 of file qhash.h.

◆ begin() [1/2]

template<typename Key , typename T >
iterator QHash< Key, T >::begin ( )
inline

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.

qhash-iterator-invalidation-func-desc

See also
constBegin(), end()

Definition at line 1237 of file qhash.h.

◆ begin() [2/2]

template<typename Key , typename T >
const_iterator QHash< Key, T >::begin ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

qhash-iterator-invalidation-func-desc

Definition at line 1238 of file qhash.h.

Referenced by QHash< Key, T >::constKeyValueBegin(), QHash< Key, T >::keyBegin(), QHash< Key, T >::keyValueBegin(), and QHash< Key, T >::keyValueBegin().

+ Here is the caller graph for this function:

◆ bucket_count()

template<typename Key , typename T >
size_t QHash< Key, T >::bucket_count ( ) const
inlinenoexcept

Definition at line 1371 of file qhash.h.

◆ cbegin()

template<typename Key , typename T >
const_iterator QHash< Key, T >::cbegin ( ) const
inlinenoexcept
Since
5.0

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.

qhash-iterator-invalidation-func-desc

See also
begin(), cend()

Definition at line 1239 of file qhash.h.

◆ cend()

template<typename Key , typename T >
const_iterator QHash< Key, T >::cend ( ) const
inlinenoexcept
Since
5.0

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the hash.

qhash-iterator-invalidation-func-desc

See also
cbegin(), end()

Definition at line 1243 of file qhash.h.

◆ constBegin()

template<typename Key , typename T >
const_iterator QHash< Key, T >::constBegin ( ) const
inlinenoexcept

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.

qhash-iterator-invalidation-func-desc

See also
begin(), constEnd()

Definition at line 1240 of file qhash.h.

◆ constEnd()

template<typename Key , typename T >
const_iterator QHash< Key, T >::constEnd ( ) const
inlinenoexcept

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the hash.

qhash-iterator-invalidation-func-desc

See also
constBegin(), end()

Definition at line 1244 of file qhash.h.

Referenced by QHash< Key, T >::erase().

+ Here is the caller graph for this function:

◆ constFind() [1/2]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
const_iterator QHash< Key, T >::constFind ( const K & key) const
inlinenoexcept

Definition at line 1464 of file qhash.h.

◆ constFind() [2/2]

template<typename Key , typename T >
const_iterator QHash< Key, T >::constFind ( const Key & key) const
inlinenoexcept
Since
4.1

Returns an iterator pointing to the item with the key in the hash.

If the hash contains no item with the key, the function returns constEnd().

qhash-iterator-invalidation-func-desc

See also
find()

Definition at line 1324 of file qhash.h.

◆ constKeyValueBegin()

template<typename Key , typename T >
const_key_value_iterator QHash< Key, T >::constKeyValueBegin ( ) const
inlinenoexcept
Since
5.10

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the hash.

qhash-iterator-invalidation-func-desc

See also
keyValueBegin()

Definition at line 1250 of file qhash.h.

References QHash< Key, T >::begin().

+ Here is the call graph for this function:

◆ constKeyValueEnd()

template<typename Key , typename T >
const_key_value_iterator QHash< Key, T >::constKeyValueEnd ( ) const
inlinenoexcept
Since
5.10

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the hash.

qhash-iterator-invalidation-func-desc

See also
constKeyValueBegin()

Definition at line 1252 of file qhash.h.

References QHash< Key, T >::end().

+ Here is the call graph for this function:

◆ contains() [1/2]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
bool QHash< Key, T >::contains ( const K & key) const
inline

Definition at line 1406 of file qhash.h.

◆ contains() [2/2]

template<typename Key , typename T >
bool QHash< Key, T >::contains ( const Key & key) const
inlinenoexcept

Returns true if the hash contains an item with the key; otherwise returns false.

See also
count()

Definition at line 1021 of file qhash.h.

◆ count() [1/3]

template<typename Key , typename T >
qsizetype QHash< Key, T >::count ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as size().

Definition at line 1315 of file qhash.h.

◆ count() [2/3]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
qsizetype QHash< Key, T >::count ( const K & key) const
inline

Definition at line 1411 of file qhash.h.

◆ count() [3/3]

template<typename Key , typename T >
qsizetype QHash< Key, T >::count ( const Key & key) const
inlinenoexcept

Returns the number of items associated with the key.

See also
contains()

Definition at line 1027 of file qhash.h.

◆ emplace() [1/2]

template<typename Key , typename T >
template<typename ... Args>
iterator QHash< Key, T >::emplace ( const Key & key,
Args &&... args )
inline

Definition at line 1349 of file qhash.h.

◆ emplace() [2/2]

template<typename Key , typename T >
template<typename ... Args>
iterator QHash< Key, T >::emplace ( Key && key,
Args &&... args )
inline

Inserts a new element into the container.

This new element is constructed in-place using args as the arguments for its construction.

Returns an iterator pointing to the new element.

qhash-iterator-invalidation-func-desc

Definition at line 1356 of file qhash.h.

◆ empty()

template<typename Key , typename T >
bool QHash< Key, T >::empty ( ) const
inlinenoexcept

This function is provided for STL compatibility.

It is equivalent to isEmpty(), returning true if the hash is empty; otherwise returns false.

Definition at line 1374 of file qhash.h.

◆ end() [1/2]

template<typename Key , typename T >
const_iterator QHash< Key, T >::end ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

qhash-iterator-invalidation-func-desc

Definition at line 1242 of file qhash.h.

Referenced by QHash< Key, T >::constKeyValueEnd(), QHash< Key, T >::keyEnd(), QHash< Key, T >::keyValueEnd(), and QHash< Key, T >::keyValueEnd().

+ Here is the caller graph for this function:

◆ end() [2/2]

template<typename Key , typename T >
iterator QHash< Key, T >::end ( )
inlinenoexcept

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the hash.

qhash-iterator-invalidation-func-desc

See also
begin(), constEnd()

Definition at line 1241 of file qhash.h.

◆ equal_range() [1/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
std::pair< iterator, iterator > QHash< Key, T >::equal_range ( const K & key)
inline

Definition at line 1443 of file qhash.h.

◆ equal_range() [2/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
std::pair< const_iterator, const_iterator > QHash< Key, T >::equal_range ( const K & key) const
inlinenoexcept

Definition at line 1449 of file qhash.h.

◆ equal_range() [3/4]

template<typename Key , typename T >
std::pair< iterator, iterator > QHash< Key, T >::equal_range ( const Key & key)
inline

Definition at line 1272 of file qhash.h.

◆ equal_range() [4/4]

template<typename Key , typename T >
std::pair< const_iterator, const_iterator > QHash< Key, T >::equal_range ( const Key & key) const
inlinenoexcept

Definition at line 1276 of file qhash.h.

◆ erase()

template<typename Key , typename T >
iterator QHash< Key, T >::erase ( const_iterator pos)
inline
Since
5.7

Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator to the next item in the hash.

This function never causes QHash to rehash its internal data structure. This means that it can safely be called while iterating, and won't affect the order of items in the hash. For example:

...
QHash<QObject *, int>::iterator i = objectHash.find(obj);
while (i != objectHash.end() && i.key() == obj) {
if (i.value() == 0) {
i = objectHash.erase(i);
} else {
++i;
}
}

qhash-iterator-invalidation-func-desc

See also
remove(), take(), find()

Definition at line 1258 of file qhash.h.

References QHash< Key, T >::constEnd().

+ Here is the call graph for this function:

◆ find() [1/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
iterator QHash< Key, T >::find ( const K & key)
inline

Definition at line 1454 of file qhash.h.

◆ find() [2/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
const_iterator QHash< Key, T >::find ( const K & key) const
inlinenoexcept

Definition at line 1459 of file qhash.h.

◆ find() [3/4]

template<typename Key , typename T >
iterator QHash< Key, T >::find ( const Key & key)
inline

Returns an iterator pointing to the item with the key in the hash.

If the hash contains no item with the key, the function returns end().

If the hash contains multiple items with the key, this function returns an iterator that points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, here's some code that iterates over all the items with the same key:

...
QHash<QString, int>::const_iterator i = hash.find("HDR");
while (i != hash.end() && i.key() == "HDR") {
cout << i.value() << endl;
++i;
}

qhash-iterator-invalidation-func-desc

See also
value(), values()

Definition at line 1316 of file qhash.h.

◆ find() [4/4]

template<typename Key , typename T >
const_iterator QHash< Key, T >::find ( const Key & key) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

qhash-iterator-invalidation-func-desc

Definition at line 1320 of file qhash.h.

◆ insert() [1/2]

template<typename Key , typename T >
iterator QHash< Key, T >::insert ( const Key & key,
const T & value )
inline

Inserts a new item with the key and a value of value.

If there is already an item with the key, that item's value is replaced with value.

Returns an iterator pointing to the new/updated element.

qhash-iterator-invalidation-func-desc

Definition at line 1328 of file qhash.h.

◆ insert() [2/2]

template<typename Key , typename T >
void QHash< Key, T >::insert ( const QHash< Key, T > & other)
inline
Since
5.15

Inserts all the items in the other hash into this hash.

If a key is common to both hashes, its value will be replaced with the value stored in other.

Definition at line 1333 of file qhash.h.

Referenced by QHash< Key, T >::QHash().

+ Here is the caller graph for this function:

◆ key() [1/2]

template<typename Key , typename T >
Key QHash< Key, T >::key ( const T & value) const
inlinenoexcept

Definition at line 1048 of file qhash.h.

◆ key() [2/2]

template<typename Key , typename T >
Key QHash< Key, T >::key ( const T & value,
const Key & defaultKey ) const
inlinenoexcept
Since
4.3

Returns the first key mapped to value. If the hash contains no item mapped to value, returns defaultKey, or a \l{default-constructed value}{default-constructed key} if this parameter has not been supplied.

This function can be slow (\l{linear time}), because QHash's internal data structure is optimized for fast lookup by key, not by value.

Definition at line 1055 of file qhash.h.

◆ keyBegin()

template<typename Key , typename T >
key_iterator QHash< Key, T >::keyBegin ( ) const
inlinenoexcept
Since
5.6

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first key in the hash.

qhash-iterator-invalidation-func-desc

See also
keyEnd()

Definition at line 1245 of file qhash.h.

References QHash< Key, T >::begin().

+ Here is the call graph for this function:

◆ keyEnd()

template<typename Key , typename T >
key_iterator QHash< Key, T >::keyEnd ( ) const
inlinenoexcept
Since
5.6

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last key in the hash.

qhash-iterator-invalidation-func-desc

See also
keyBegin()

Definition at line 1246 of file qhash.h.

References QHash< Key, T >::end().

+ Here is the call graph for this function:

◆ keys() [1/2]

template<typename Key , typename T >
QList< Key > QHash< Key, T >::keys ( ) const
inline

Returns a list containing all the keys in the hash, in an arbitrary order.

The order is guaranteed to be the same as that used by values().

This function creates a new list, in \l {linear time}. The time and memory use that entails can be avoided by iterating from \l keyBegin() to \l keyEnd().

See also
values(), key()

Definition at line 1113 of file qhash.h.

◆ keys() [2/2]

template<typename Key , typename T >
QList< Key > QHash< Key, T >::keys ( const T & value) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list containing all the keys associated with value value, in an arbitrary order.

This function can be slow (\l{linear time}), because QHash's internal data structure is optimized for fast lookup by key, not by value.

Definition at line 1114 of file qhash.h.

◆ keyValueBegin() [1/2]

template<typename Key , typename T >
key_value_iterator QHash< Key, T >::keyValueBegin ( )
inline
Since
5.10

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the hash.

qhash-iterator-invalidation-func-desc

See also
keyValueEnd()

Definition at line 1247 of file qhash.h.

References QHash< Key, T >::begin().

+ Here is the call graph for this function:

◆ keyValueBegin() [2/2]

template<typename Key , typename T >
const_key_value_iterator QHash< Key, T >::keyValueBegin ( ) const
inlinenoexcept
Since
5.10

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the hash.

qhash-iterator-invalidation-func-desc

See also
keyValueEnd()

Definition at line 1249 of file qhash.h.

References QHash< Key, T >::begin().

+ Here is the call graph for this function:

◆ keyValueEnd() [1/2]

template<typename Key , typename T >
key_value_iterator QHash< Key, T >::keyValueEnd ( )
inline
Since
5.10

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the hash.

qhash-iterator-invalidation-func-desc

See also
keyValueBegin()

Definition at line 1248 of file qhash.h.

References QHash< Key, T >::end().

+ Here is the call graph for this function:

◆ keyValueEnd() [2/2]

template<typename Key , typename T >
const_key_value_iterator QHash< Key, T >::keyValueEnd ( ) const
inlinenoexcept
Since
5.10

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the hash.

qhash-iterator-invalidation-func-desc

See also
keyValueBegin()

Definition at line 1251 of file qhash.h.

References QHash< Key, T >::end().

+ Here is the call graph for this function:

◆ load_factor()

template<typename Key , typename T >
float QHash< Key, T >::load_factor ( ) const
inlinenoexcept

Returns the current load factor of the QHash's internal hash table.

This is the same as capacity()/size(). The implementation used will aim to keep the load factor between 0.25 and 0.5. This avoids having too many hash table collisions that would degrade performance.

Even with a low load factor, the implementation of the hash table has a very low memory overhead.

This method purely exists for diagnostic purposes and you should rarely need to call it yourself.

See also
reserve(), squeeze()

Definition at line 1369 of file qhash.h.

◆ max_bucket_count()

template<typename Key , typename T >
static size_t QHash< Key, T >::max_bucket_count ( )
inlinestaticnoexcept

Definition at line 1372 of file qhash.h.

◆ max_load_factor()

template<typename Key , typename T >
static float QHash< Key, T >::max_load_factor ( )
inlinestaticnoexcept

Definition at line 1370 of file qhash.h.

◆ operator=()

template<typename Key , typename T >
QHash & QHash< Key, T >::operator= ( const QHash< Key, T > & other)
inlinenoexcept

Assigns other to this hash and returns a reference to this hash.

Move-assigns other to this QHash instance.

Since
5.2

Definition at line 861 of file qhash.h.

◆ operator[]() [1/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true, if_key_constructible_from< K > = true>
T & QHash< Key, T >::operator[] ( const K & key)
inline

Definition at line 1432 of file qhash.h.

◆ operator[]() [2/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
const T QHash< Key, T >::operator[] ( const K & key) const
inlinenoexcept

Definition at line 1437 of file qhash.h.

◆ operator[]() [3/4]

template<typename Key , typename T >
T & QHash< Key, T >::operator[] ( const Key & key)
inline

Returns the value associated with the key as a modifiable reference.

If the hash contains no item with the key, the function inserts a \l{default-constructed value} into the hash with the key, and returns a reference to it.

! [qhash-iterator-invalidation-func-desc]

Warning
Returned iterators/references should be considered invalidated the next time you call a non-const function on the hash, or when the hash is destroyed. ! [qhash-iterator-invalidation-func-desc]
\sa insert(), value()

Definition at line 1091 of file qhash.h.

◆ operator[]() [4/4]

template<typename Key , typename T >
const T QHash< Key, T >::operator[] ( const Key & key) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as value().

Definition at line 1108 of file qhash.h.

◆ remove()

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
bool QHash< Key, T >::remove ( const K & key)
inline

Definition at line 1396 of file qhash.h.

◆ removeIf()

template<typename Key , typename T >
template<typename Predicate >
qsizetype QHash< Key, T >::removeIf ( Predicate pred)
inline
Since
6.1

Removes all elements for which the predicate pred returns true from the hash.

The function supports predicates which take either an argument of type {QHash<Key, T>::iterator}, or an argument of type {std::pair<const Key &, T &>}.

Returns the number of elements removed, if any.

See also
clear(), take()

Definition at line 994 of file qhash.h.

◆ swap()

template<typename Key , typename T >
void QHash< Key, T >::swap ( QHash< Key, T > & other)
inlinenoexcept
Since
4.8 \memberswap{hash}

Definition at line 904 of file qhash.h.

◆ take() [1/2]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
T QHash< Key, T >::take ( const K & key)
inline

Definition at line 1401 of file qhash.h.

◆ take() [2/2]

template<typename Key , typename T >
T QHash< Key, T >::take ( const Key & key)
inline

Removes the item with the key from the hash and returns the value associated with it.

If the item does not exist in the hash, the function simply returns a \l{default-constructed value}.

If you don't use the return value, remove() is more efficient.

See also
remove()

Definition at line 999 of file qhash.h.

◆ value() [1/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
T QHash< Key, T >::value ( const K & key) const
inlinenoexcept

Definition at line 1416 of file qhash.h.

◆ value() [2/4]

template<typename Key , typename T >
template<typename K , if_heterogeneously_searchable< K > = true>
T QHash< Key, T >::value ( const K & key,
const T & defaultValue ) const
inlinenoexcept

Definition at line 1424 of file qhash.h.

◆ value() [3/4]

template<typename Key , typename T >
T QHash< Key, T >::value ( const Key & key) const
inlinenoexcept

Definition at line 1075 of file qhash.h.

◆ value() [4/4]

template<typename Key , typename T >
T QHash< Key, T >::value ( const Key & key,
const T & defaultValue ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the value associated with the key.

If the hash contains no item with the key, the function returns defaultValue, or a \l{default-constructed value} if this parameter has not been supplied.

Definition at line 1083 of file qhash.h.

◆ values()

template<typename Key , typename T >
QList< T > QHash< Key, T >::values ( ) const
inline

Returns a list containing all the values in the hash, in an arbitrary order.

The order is guaranteed to be the same as that used by keys().

This function creates a new list, in \l {linear time}. The time and memory use that entails can be avoided by iterating from \l keyValueBegin() to \l keyValueEnd().

See also
keys(), value()

Definition at line 1125 of file qhash.h.

Friends And Related Symbol Documentation

◆ comparesEqual

template<typename Key , typename T >
template<typename AKey = Key, typename AT = T, QTypeTraits::compare_eq_result_container< QHash, AKey, AT > = true>
bool comparesEqual ( const QHash< Key, T > & lhs,
const QHash< Key, T > & rhs )
friend

Definition at line 917 of file qhash.h.

◆ const_iterator

template<typename Key , typename T >
friend class const_iterator
friend

Definition at line 1207 of file qhash.h.

◆ erase_if()

template<typename Key , typename T >
template< typename Key, typename T, typename Predicate > qsizetype erase_if ( QHash< Key, T > & hash,
Predicate pred )
related
Since
6.1

Removes all elements for which the predicate pred returns true from the hash hash.

The function supports predicates which take either an argument of type {QHash<Key, T>::iterator}, or an argument of type {std::pair<const Key &, T &>}.

Returns the number of elements removed, if any.

Definition at line 2556 of file qhash.h.

◆ iterator

template<typename Key , typename T >
friend class iterator
friend

Definition at line 1167 of file qhash.h.

◆ operator<<()

template<typename Key , typename T >
template< class Key, class T > QDataStream & operator<< ( QDataStream & out,
const QHash< Key, T > & hash )
related

Writes the hash hash to stream out.

This function requires the key and value types to implement operator<<().

See also
{Serializing Qt Data Types}

Definition at line 571 of file qdatastream.h.

◆ operator>>()

template<typename Key , typename T >
template< class Key, class T > QDataStream & operator>> ( QDataStream & in,
QHash< Key, T > & hash )
related

Reads a hash from stream in into hash.

This function requires the key and value types to implement operator>>().

See also
{Serializing Qt Data Types}

Definition at line 571 of file qdatastream.h.

◆ qHash() [1/43]

template<typename Key , typename T >
size_t qHash ( char key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 104 of file qhashfunctions.h.

◆ qHash() [2/43]

template<typename Key , typename T >
size_t qHash ( char16_t key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 174 of file qhashfunctions.h.

◆ qHash() [3/43]

template<typename Key , typename T >
size_t qHash ( char32_t key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 176 of file qhashfunctions.h.

◆ qHash() [4/43]

template<typename Key , typename T >
size_t qHash ( char8_t key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [5/43]

template<typename Key , typename T >
size_t qHash ( const QBitArray & key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [6/43]

template<typename Key , typename T >
size_t qHash ( const QByteArray & key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 202 of file qhashfunctions.h.

◆ qHash() [7/43]

template<typename Key , typename T >
size_t qHash ( const QByteArrayView & key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [8/43]

template<typename Key , typename T >
size_t qHash ( const QChar key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 195 of file qhashfunctions.h.

◆ qHash() [9/43]

template<typename Key , typename T >
size_t qHash ( const QDateTime & key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [10/43]

template<typename Key , typename T >
size_t qHash ( const QGeoCoordinate & coordinate,
size_t seed = 0 )
related

Returns a hash value for coordinate, using seed to seed the calculation.

◆ qHash() [11/43]

template<typename Key , typename T >
template< class Key, class T > size_t qHash ( const QHash< Key, T > & key,
size_t seed = 0 )
related
Since
5.8

Returns the hash value for the key, using seed to seed the calculation.

Type T must be supported by qHash().

Definition at line 2528 of file qhash.h.

◆ qHash() [12/43]

template<typename Key , typename T >
size_t qHash ( const QOcspResponse & response,
size_t seed )
related

Returns the hash value for the response, using seed to seed the calculation.

Since
5.13

Definition at line 208 of file qocspresponse.cpp.

◆ qHash() [13/43]

template<typename Key , typename T >
size_t qHash ( const QSslCertificate & key,
size_t seed )
related

Returns the hash value for the key, using seed to seed the calculation.

Since
5.4

Definition at line 978 of file qsslcertificate.cpp.

◆ qHash() [14/43]

template<typename Key , typename T >
size_t qHash ( const QSslError & key,
size_t seed )
related

Returns the hash value for the key, using seed to seed the calculation.

Since
5.4

Definition at line 334 of file qsslerror.cpp.

◆ qHash() [15/43]

template<typename Key , typename T >
size_t qHash ( const QString & key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 208 of file qhashfunctions.h.

◆ qHash() [16/43]

template<typename Key , typename T >
size_t qHash ( const QTypeRevision & key,
size_t seed )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 212 of file qtyperevision.cpp.

◆ qHash() [17/43]

template<typename Key , typename T >
size_t qHash ( const QUrl & url,
size_t seed )
related

Returns the hash value for the url.

If specified, seed is used to initialize the hash.

Since
5.0

Definition at line 3625 of file qurl.cpp.

◆ qHash() [18/43]

template<typename Key , typename T >
size_t qHash ( const QVersionNumber & key,
size_t seed )
related
Since
5.6

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 580 of file qversionnumber.cpp.

◆ qHash() [19/43]

template<typename Key , typename T >
template< typename T1, typename T2 > size_t qHash ( const std::pair< T1, T2 > & key,
size_t seed = 0 )
related
Since
5.7

Returns the hash value for the key, using seed to seed the calculation.

Types T1 and T2 must be supported by qHash().

Definition at line 395 of file qhashfunctions.h.

◆ qHash() [20/43]

template<typename Key , typename T >
template< class T > size_t qHash ( const T * key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 182 of file qhashfunctions.h.

◆ qHash() [21/43]

template<typename Key , typename T >
size_t qHash ( double key,
size_t seed )
related
Since
5.3

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 1400 of file qhash.cpp.

◆ qHash() [22/43]

template<typename Key , typename T >
size_t qHash ( float key,
size_t seed = 0 )
related
Since
5.3

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 162 of file qhashfunctions.h.

◆ qHash() [23/43]

template<typename Key , typename T >
size_t qHash ( int key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 116 of file qhashfunctions.h.

◆ qHash() [24/43]

template<typename Key , typename T >
size_t qHash ( long double key,
size_t seed )
related
Since
5.3

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 1418 of file qhash.cpp.

◆ qHash() [25/43]

template<typename Key , typename T >
size_t qHash ( long key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 120 of file qhashfunctions.h.

◆ qHash() [26/43]

template<typename Key , typename T >
size_t qHash ( QDate key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [27/43]

template<typename Key , typename T >
size_t qHash ( qint128 key,
size_t seed = 0 )
related
Since
6.8

Returns the hash value for the key, using seed to seed the calculation.

Note
This function is only available on platforms that support a native 128-bit integer type.

◆ qHash() [28/43]

template<typename Key , typename T >
size_t qHash ( qint64 key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 129 of file qhashfunctions.h.

◆ qHash() [29/43]

template<typename Key , typename T >
size_t qHash ( QLatin1StringView key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [30/43]

template<typename Key , typename T >
size_t qHash ( QPoint key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [31/43]

template<typename Key , typename T >
size_t qHash ( QSslEllipticCurve curve,
size_t seed = 0 )
related
Since
5.5

Returns an hash value for the curve curve, using seed to seed the calculation.

Definition at line 53 of file qsslellipticcurve.h.

◆ qHash() [32/43]

template<typename Key , typename T >
size_t qHash ( QTime key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

◆ qHash() [33/43]

template<typename Key , typename T >
size_t qHash ( quint128 key,
size_t seed = 0 )
related
Since
6.8

Returns the hash value for the key, using seed to seed the calculation.

Note
This function is only available on platforms that support a native 128-bit integer type.

◆ qHash() [34/43]

template<typename Key , typename T >
size_t qHash ( quint64 key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 123 of file qhashfunctions.h.

◆ qHash() [35/43]

template<typename Key , typename T >
size_t qHash ( short key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 112 of file qhashfunctions.h.

◆ qHash() [36/43]

template<typename Key , typename T >
size_t qHash ( signed char key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 108 of file qhashfunctions.h.

◆ qHash() [37/43]

template<typename Key , typename T >
size_t qHash ( std::nullptr_t key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 186 of file qhashfunctions.h.

◆ qHash() [38/43]

template<typename Key , typename T >
template< typname T, std::enable_if_t< std::is_same_v< T, bool >, bool >=true > size_t qHash ( T key,
size_t seed )
related
Since
6.9

Returns the hash value for the key, using seed to seed the calculation.

Note
This is qHash(bool), constrained to accept only arguments of type bool, not arguments of types that merely convert to bool.
In Qt versions prior to 6.9, this overload was unintendedly provided by an undocumented 1-to-2-arg qHash adapter template function, with identical behavior.

◆ qHash() [39/43]

template<typename Key , typename T >
size_t qHash ( uchar key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 106 of file qhashfunctions.h.

◆ qHash() [40/43]

template<typename Key , typename T >
size_t qHash ( uint key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 114 of file qhashfunctions.h.

◆ qHash() [41/43]

template<typename Key , typename T >
size_t qHash ( ulong key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 118 of file qhashfunctions.h.

◆ qHash() [42/43]

template<typename Key , typename T >
size_t qHash ( ushort key,
size_t seed = 0 )
related
Since
5.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 110 of file qhashfunctions.h.

◆ qHash() [43/43]

template<typename Key , typename T >
size_t qHash ( wchar_t key,
size_t seed = 0 )
related
Since
6.0

Returns the hash value for the key, using seed to seed the calculation.

Definition at line 172 of file qhashfunctions.h.

◆ qHashBits()

template<typename Key , typename T >
size_t qHashBits ( const void * p,
size_t len,
size_t seed = 0 )
related
Since
5.4

Returns the hash value for the memory block of size len pointed to by p, using seed to seed the calculation.

Use this function only to implement qHash() for your own custom types. For example, here's how you could implement a qHash() overload for std::vector<int>:

inline size_t qHash(const std::vector<int> &key, size_t seed = 0)
{
if (key.empty())
return seed;
else
return qHashBits(&key.front(), key.size() * sizeof(int), seed);
}

This takes advantage of the fact that std::vector lays out its data contiguously. If that is not the case, or the contained type has padding, you should use qHashRange() instead.

It bears repeating that the implementation of qHashBits() - like the qHash() overloads offered by Qt - may change at any time. You {must not} rely on the fact that qHashBits() will give the same results (for the same inputs) across different Qt versions.

See also
qHashRange(), qHashRangeCommutative()

◆ qHashEquals()

template<typename Key , typename T >
template< typename T > bool qHashEquals ( const T & a,
const T & b )
related
Since
6.0

This method is being used by QHash to compare two keys. Returns true if the keys a and b are considered equal for hashing purposes.

The default implementation returns the result of (a == b). It can be reimplemented for a certain type if the equality operator is not suitable for hashing purposes. This is for example the case if the equality operator uses qFuzzyCompare to compare floating point values.

Definition at line 287 of file qhashfunctions.h.

◆ qHashMulti()

template<typename Key , typename T >
template< typename... T > size_t qHashMulti ( size_t seed,
const T &... args )
related
Since
6.0

Returns the hash value for the {args}, using seed to seed the calculation, by successively applying qHash() to each element and combining the hash values into a single one.

Note that the order of the arguments is significant. If order does not matter, use qHashMultiCommutative() instead. If you are hashing raw memory, use qHashBits(); if you are hashing a range, use qHashRange().

This function is provided as a convenience to implement qHash() for your own custom types. For example, here's how you could implement a qHash() overload for a class {Employee}:

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
public:
Employee() {}
Employee(const QString &name, QDate dateOfBirth);
...
private:
QString myName;
QDate myDateOfBirth;
};
inline bool operator==(const Employee &e1, const Employee &e2)
{
return e1.name() == e2.name()
&& e1.dateOfBirth() == e2.dateOfBirth();
}
inline size_t qHash(const Employee &key, size_t seed)
{
return qHashMulti(seed, key.name(), key.dateOfBirth());
}
#endif // EMPLOYEE_H
See also
qHashMultiCommutative, qHashRange

Definition at line 352 of file qhashfunctions.h.

◆ qHashMultiCommutative()

template<typename Key , typename T >
template< typename... T > size_t qHashMultiCommutative ( size_t seed,
const T &... args )
related
Since
6.0

Returns the hash value for the {args}, using seed to seed the calculation, by successively applying qHash() to each element and combining the hash values into a single one.

The order of the arguments is insignificant. If order does matter, use qHashMulti() instead, as it may produce better quality hashing. If you are hashing raw memory, use qHashBits(); if you are hashing a range, use qHashRange().

This function is provided as a convenience to implement qHash() for your own custom types.

See also
qHashMulti, qHashRange

Definition at line 366 of file qhashfunctions.h.

◆ qHashRange()

template<typename Key , typename T >
template< typename InputIterator > size_t qHashRange ( InputIterator first,
InputIterator last,
size_t seed = 0 )
related
Since
5.5

Returns the hash value for the range [{first},{last}), using seed to seed the calculation, by successively applying qHash() to each element and combining the hash values into a single one.

The return value of this function depends on the order of elements in the range. That means that

{0, 1, 2}

and

{1, 2, 0}

hash to {different} values. If order does not matter, for example for hash tables, use qHashRangeCommutative() instead. If you are hashing raw memory, use qHashBits().

Use this function only to implement qHash() for your own custom types. For example, here's how you could implement a qHash() overload for std::vector<int>:

inline size_t qHash(const std::vector<int> &key, size_t seed = 0)
{
return qHashRange(key.begin(), key.end(), seed);
}

It bears repeating that the implementation of qHashRange() - like the qHash() overloads offered by Qt - may change at any time. You {must not} rely on the fact that qHashRange() will give the same results (for the same inputs) across different Qt versions, even if qHash() for the element type would.

See also
qHashBits(), qHashRangeCommutative()

Definition at line 374 of file qhashfunctions.h.

◆ qHashRangeCommutative()

template<typename Key , typename T >
template< typename InputIterator > size_t qHashRangeCommutative ( InputIterator first,
InputIterator last,
size_t seed = 0 )
related
Since
5.5

Returns the hash value for the range [{first},{last}), using seed to seed the calculation, by successively applying qHash() to each element and combining the hash values into a single one.

The return value of this function does not depend on the order of elements in the range. That means that

{0, 1, 2}

and

{1, 2, 0}

hash to the {same} values. If order matters, for example, for vectors and arrays, use qHashRange() instead. If you are hashing raw memory, use qHashBits().

Use this function only to implement qHash() for your own custom types. For example, here's how you could implement a qHash() overload for std::unordered_set<int>:

inline size_t qHash(const std::unordered_set<int> &key, size_t seed = 0)
{
return qHashRangeCommutative(key.begin(), key.end(), seed);
}

It bears repeating that the implementation of qHashRangeCommutative() - like the qHash() overloads offered by Qt

  • may change at any time. You {must not} rely on the fact that qHashRangeCommutative() will give the same results (for the same inputs) across different Qt versions, even if qHash() for the element type would.
See also
qHashBits(), qHashRange()

Definition at line 381 of file qhashfunctions.h.

◆ QMultiHash< Key, T >

template<typename Key , typename T >
friend class QMultiHash< Key, T >
friend

Definition at line 811 of file qhash.h.

◆ QSet< Key >

template<typename Key , typename T >
friend class QSet< Key >
friend

Definition at line 811 of file qhash.h.


The documentation for this class was generated from the following files: