Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

const_iterator Class

(QHash::const_iterator)

TheQHash::const_iterator class provides an STL-style const iterator forQHash andQMultiHash.More...

Header:#include <const_iterator>

Public Functions

const_iterator()
const_iterator(const iterator & other)
const Key &key() const
const T &value() const
booloperator!=(const const_iterator & other) const
const T &operator*() const
const_iteratoroperator+(int j) const
const_iterator &operator++()
const_iteratoroperator++(int)
const_iterator &operator+=(int j)
const_iteratoroperator-(int j) const
const_iterator &operator--()
const_iteratoroperator--(int)
const_iterator &operator-=(int j)
const T *operator->() const
booloperator==(const const_iterator & other) const

Detailed Description

TheQHash::const_iterator class provides an STL-style const iterator forQHash andQMultiHash.

QHash features bothSTL-style iterators andJava-style iterators. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.

QHash<Key, T>::const_iterator allows you to iterate over aQHash (or aQMultiHash). If you want to modify theQHash as you iterate over it, you must useQHash::iterator instead. It is generally good practice to useQHash::const_iterator on a non-constQHash as well, unless you need to change theQHash through the iterator. Const iterators are slightly faster, and can improve code readability.

The defaultQHash::const_iterator constructor creates an uninitialized iterator. You must initialize it using aQHash function likeQHash::constBegin(),QHash::constEnd(), orQHash::find() before you can start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a hash:

QHash<QString,int> hash;hash.insert("January",1);hash.insert("February",2);...hash.insert("December",12);QHash<QString,int>::const_iterator i;for (i= hash.constBegin(); i!= hash.constEnd();++i)    cout<< i.key()<<": "<< i.value()<< endl;

UnlikeQMap, which orders its items by key,QHash stores its items in an arbitrary order. The only guarantee is that items that share the same key (because they were inserted usingQHash::insertMulti()) will appear consecutively, from the most recently to the least recently inserted value.

Multiple iterators can be used on the same hash. However, be aware that any modification performed directly on theQHash has the potential of dramatically changing the order in which the items are stored in the hash, as they might causeQHash to rehash its internal data structure. If you need to keep iterators over a long period of time, we recommend that you useQMap rather thanQHash.

See alsoQHash::iterator andQHashIterator.

Member Function Documentation

const_iterator::const_iterator()

Constructs an uninitialized iterator.

Functions likekey(),value(), and operator++() must not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it.

See alsoQHash::constBegin() andQHash::constEnd().

const_iterator::const_iterator(constiterator & other)

Constructs a copy ofother.

constKey & const_iterator::key() const

Returns the current item's key.

See alsovalue().

constT & const_iterator::value() const

Returns the current item's value.

See alsokey() andoperator*().

bool const_iterator::operator!=(constconst_iterator & other) const

Returns true ifother points to a different item than this iterator; otherwise returns false.

See alsooperator==().

constT & const_iterator::operator*() const

Returns the current item's value.

Same asvalue().

See alsokey().

const_iterator const_iterator::operator+(int j) const

Returns an iterator to the item atj positions forward from this iterator. (Ifj is negative, the iterator goes backward.)

This operation can be slow for largej values.

See alsooperator-().

const_iterator & const_iterator::operator++()

The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterator to the new current item.

Calling this function onQHash::end() leads to undefined results.

See alsooperator--().

const_iterator const_iterator::operator++(int)

This is an overloaded function.

The postfix ++ operator (i++) advances the iterator to the next item in the hash and returns an iterator to the previously current item.

const_iterator & const_iterator::operator+=(int j)

Advances the iterator byj items. (Ifj is negative, the iterator goes backward.)

This operation can be slow for largej values.

See alsooperator-=() andoperator+().

const_iterator const_iterator::operator-(int j) const

Returns an iterator to the item atj positions backward from this iterator. (Ifj is negative, the iterator goes forward.)

This operation can be slow for largej values.

See alsooperator+().

const_iterator & const_iterator::operator--()

The prefix -- operator (--i) makes the preceding item current and returns an iterator pointing to the new current item.

Calling this function onQHash::begin() leads to undefined results.

See alsooperator++().

const_iterator const_iterator::operator--(int)

This is an overloaded function.

The postfix -- operator (i--) makes the preceding item current and returns an iterator pointing to the previously current item.

const_iterator & const_iterator::operator-=(int j)

Makes the iterator go back byj items. (Ifj is negative, the iterator goes forward.)

This operation can be slow for largej values.

See alsooperator+=() andoperator-().

constT * const_iterator::operator->() const

Returns a pointer to the current item's value.

See alsovalue().

bool const_iterator::operator==(constconst_iterator & other) const

Returns true ifother points to the same item as this iterator; otherwise returns false.

See alsooperator!=().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp