QHash::key_iterator Class
class QHash::key_iteratorQHash::key_iterator 클래스는 ` QHash ` 키에 대해 STL 스타일의 const 이터레이터를 제공합니다. 더 보기...
공개 함수
| key_iterator() | |
| QHash<Key, T>::const_iterator | base() const |
| bool | operator!=(QHash<Key, T>::key_iterator other) const |
| const Key & | operator*() const |
| QHash<Key, T>::key_iterator & | operator++() |
| QHash<Key, T>::key_iterator | operator++(int) |
| const Key * | operator->() const |
| bool | operator==(QHash<Key, T>::key_iterator other) const |
상세 설명
QHash::key_iterator QHash::const_iterator 와 본질적으로 동일하지만, operator*() 및 operator->()가 값 대신 키를 반환한다는 점이 다릅니다.
대부분의 경우 QHash::iterator 와 QHash::const_iterator 를 사용해야 하며, QHash::iterator::key()를 호출하여 키에 쉽게 접근할 수 있습니다:
for (auto it = hash.cbegin(), end = hash.cend(); it != end; ++it) {
cout << "The key: " << it.key() << endl;
cout << "The value: " << qPrintable(it.value()) << endl;
cout << "Also the value: " << qPrintable(*it) << endl;
}그러나 QHash 의 키와 STL 스타일 알고리즘 간의 상호 운용성을 확보하려면, 값 대신 키를 참조하는 이터레이터가 필요합니다. QHash::key_iterator 를 사용하면 QHash::keys()을 호출하지 않고도 키 범위에 알고리즘을 적용할 수 있습니다. () 호출은 QHash 반복을 한 번 수행해야 하고, 임시 객체 QList 를 생성하기 위해 메모리를 할당해야 하므로 비효율적입니다.
// 비효율적, keys() 호출 비용이 큼
QList<int> keys = hash.keys();
int numPrimes = std::count_if(keys.cbegin(), keys.cend(), isPrimeNumber);
qDeleteAll(hash2.keys());
// 효율적이며, 메모리 할당이 필요 없음
int primeNums = std::count_if(hash.keyBegin(), hash.keyEnd(), isPrimeNumber);
qDeleteAll(hash2.keyBegin(), hash2.keyEnd());QHash::key_iterator const인 경우, 키를 수정할 수 없습니다.
QHash::key_iterator 의 기본 생성자는 초기화되지 않은 이터레이터를 생성합니다. QHash::keyBegin()이나 QHash::keyEnd()과 같은 QHash 함수를 사용하여 이터레이터를 초기화해야 합니다.
경고: 암시적으로 공유되는 컨테이너의이터레이터는 STL 이터레이터와 정확히 동일하게 작동하지 않습니다. 해당 컨테이너에서 이터레이터가 활성화된 상태에서는 컨테이너를 복사하지 않도록 해야 합니다. 자세한 내용은 ‘암시적 공유 이터레이터 문제’를 참조하십시오.
QHash::const_iterator 및 QHash::iterator도 참조하십시오 .
멤버 함수 문서
[noexcept default] key_iterator::key_iterator()
key_iterator 의 인스턴스를 기본 생성합니다.
[noexcept] QHash<Key, T>::const_iterator key_iterator::base() const
이 ` key_iterator `의 기반이 되는 ` const_iterator `를 반환합니다.
[noexcept] bool key_iterator::operator!=(QHash<Key, T>::key_iterator other) const
other 가 이 이터레이터와 다른 항목을 가리키는 경우 true 를 반환하고, 그렇지 않은 경우 false 를 반환합니다.
operator==()도 참조하십시오 .
[noexcept] const Key &key_iterator::operator*() const
현재 항목의 키를 반환합니다.
[noexcept] QHash<Key, T>::key_iterator &key_iterator::operator++()
접두사 ++ 연산자(++i)는 이터레이터를 해시 내의 다음 항목으로 이동시키고, 새로운 현재 항목에 대한 이터레이터를 반환합니다.
QHash::keyEnd()에서 이 함수를 호출하면 정의되지 않은 결과가 발생합니다.
[noexcept] QHash<Key, T>::key_iterator key_iterator::operator++(int)
후치 연산자 ++ (i++)는 이터레이터를 해시의 다음 항목으로 이동시키고, 이전 항목에 대한 이터레이터를 반환합니다.
이는 오버로드된 함수입니다.
[noexcept] const Key *key_iterator::operator->() const
현재 항목의 키에 대한 포인터를 반환합니다.
[noexcept] bool key_iterator::operator==(QHash<Key, T>::key_iterator other) const
other 가 이 반복자와 동일한 항목을 가리키는 경우 true 를 반환하고, 그렇지 않은 경우 false 를 반환합니다.
operator!=()도 참조하십시오 .
© 2026 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 the GNU 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.