QSet Class▲
-
Header: QSet
-
qmake: QT += core
-
Group: QSet is part of tools, https://
Detailed Description▲
https://<T> is one of Qt's generic https://. It stores values in an unspecified order and provides very fast lookup of the values. Internally, https://<T> is implemented as a https://.
Here's an example https:// with QString values:
QSet<QString> set;To insert a value into the set, use https://():
set.insert("one");
set.insert("three");
set.insert("seven");Another way to insert items into the set is to use operator<<():
set << "twelve" << "fifteen" << "nineteen";To test whether an item belongs to the set or not, use https://():
if (!set.contains("ninety-nine"))
...If you want to navigate through all the values stored in a https://, you can use an iterator. https:// supports both https:// (https:// and https://) and https:// (https:// and https://). Here's how to iterate over a https://<QWidget *> using a Java-style iterator:
QSetIterator<QWidget *> i(set);
while (i.hasNext())
qDebug() << i.next();Here's the same code, but using an STL-style iterator:
QSet<QWidget *>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
qDebug() << *i;
++i;
}https:// is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a https://.
To navigate through a https://, you can also use https://:
QSet<QString> set;
...
foreach (const QString &value, set)
qDebug() << value;Items can be removed from the set using https://(). There is also a https://() function that removes all items.
https://'s value data type must be an https://. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. In addition, the type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type. See the https:// documentation for a list of types supported by qHash().
Internally, https:// uses a hash table to perform lookups. The hash table automatically grows and shrinks to provide fast lookups without wasting memory. You can still control the size of the hash table by calling https://(), if you already know approximately how many elements the https:// will contain, but this isn't necessary to obtain good performance. You can also call https://() to retrieve the hash table's size.
See Also▲
See also https://, https://, https://, https://
Member Type Documentation▲
QSet::ConstIterator▲
Qt-style synonym for https://.
[since 4.2] QSet::Iterator▲
Qt-style synonym for https://.
This typedef was introduced in Qt 4.2.
QSet::const_pointer▲
Typedef for const T *. Provided for STL compatibility.
QSet::const_reference▲
Typedef for const T &. Provided for STL compatibility.
[since 5.6] QSet::const_reverse_iterator▲
The QSet::const_reverse_iterator typedef provides an STL-style const reverse iterator for https://.
It is simply a typedef for std::reverse_iterator<QSet::const_iterator>.
Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.
This typedef was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://, https://
QSet::difference_type▲
Typedef for const ptrdiff_t. Provided for STL compatibility.
QSet::key_type▲
Typedef for T. Provided for STL compatibility.
QSet::pointer▲
Typedef for T *. Provided for STL compatibility.
QSet::reference▲
Typedef for T &. Provided for STL compatibility.
[since 5.6] QSet::reverse_iterator▲
The QSet::reverse_iterator typedef provides an STL-style non-const reverse iterator for https://.
It is simply a typedef for std::reverse_iterator<QSet::iterator>.
Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read https://.
This typedef was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://, https://
QSet::size_type▲
Typedef for int. Provided for STL compatibility.
QSet::value_type▲
Typedef for T. Provided for STL compatibility.
Member Function Documentation▲
QSet<T> &QSet::operator+=(const T &value)▲
QSet<T> &QSet::operator<<(const T &value)
QSet<T> &QSet::operator|=(const T &value)
Inserts a new item value and returns a reference to the set. If value already exists in the set, the set is left unchanged.
See Also▲
See also https://()
QSet<T> &QSet::operator+=(const QSet<T> &other)▲
QSet<T> &QSet::operator|=(const QSet<T> &other)
Same as unite(other).
See Also▲
See also https://(), https://(), https://()
QSet<T> QSet::operator+(const QSet<T> &other) const▲
QSet<T> QSet::operator|(const QSet<T> &other) const
Returns a new https:// that is the union of this set and the other set.
See Also▲
See also https://(), https://(), https://(), https://()
QSet::QSet()▲
[since 5.1] QSet::QSet(std::initializer_list<T> list)▲
Constructs a set with a copy of each of the elements in the initializer list list.
This function was introduced in Qt 5.1.
[since 5.14] QSet::QSet(InputIterator first, InputIterator last)▲
Constructs a set with the contents in the iterator range [first, last).
The value type of InputIterator must be convertible to T.
If the range [first, last) contains duplicate elements, the first one is retained.
This function was introduced in Qt 5.14.
QSet::const_iterator QSet::begin() const▲
Returns a const https:// positioned at the first item in the set.
See Also▲
See also https://(), https://()
[since 4.2] QSet::iterator QSet::begin()▲
This is an overloaded function.
Returns a non-const https:// positioned at the first item in the set.
This function was introduced in Qt 4.2.
int QSet::capacity() const▲
Returns the number of buckets in the set's internal hash table.
The sole purpose of this function is to provide a means of fine tuning https://'s memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the set, call https://().
See Also▲
See also https://(), https://()
[since 5.0] QSet::const_iterator QSet::cbegin() const▲
Returns a const https:// positioned at the first item in the set.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://()
[since 5.0] QSet::const_iterator QSet::cend() const▲
Returns a const https:// pointing to the imaginary item after the last item in the set.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://()
void QSet::clear()▲
QSet::const_iterator QSet::constBegin() const▲
Returns a const https:// positioned at the first item in the set.
See Also▲
See also https://(), https://()
QSet::const_iterator QSet::constEnd() const▲
Returns a const https:// pointing to the imaginary item after the last item in the set.
See Also▲
See also https://(), https://()
[since 4.2] QSet::const_iterator QSet::constFind(const T &value) const▲
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the function returns https://().
This function was introduced in Qt 4.2.
See Also▲
See also https://(), https://()
bool QSet::contains(const T &value) const▲
Returns true if the set contains item value; otherwise returns false.
See Also▲
See also https://(), https://(), https://()
[since 4.6] bool QSet::contains(const QSet<T> &other) const▲
Returns true if the set contains all items from the other set; otherwise returns false.
This function was introduced in Qt 4.6.
See Also▲
See also https://(), https://(), https://()
int QSet::count() const▲
Same as https://().
[since 5.6] QSet::const_reverse_iterator QSet::crbegin() const▲
Returns a const https:// reverse iterator pointing to the first item in the set, in reverse order.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://()
[since 5.6] QSet::const_reverse_iterator QSet::crend() const▲
Returns a const https:// reverse iterator pointing to one past the last item in the set, in reverse order.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://()
bool QSet::empty() const▲
Returns true if the set is empty. This function is provided for STL compatibility. It is equivalent to https://().
QSet::const_iterator QSet::end() const▲
Returns a const https:// positioned at the imaginary item after the last item in the set.
See Also▲
See also https://(), https://()
[since 4.2] QSet::iterator QSet::end()▲
This is an overloaded function.
Returns a non-const https:// pointing to the imaginary item after the last item in the set.
This function was introduced in Qt 4.2.
[since 5.7] QSet::iterator QSet::erase(QSet::const_iterator pos)▲
Removes the item at the iterator position pos from the set, and returns an iterator positioned at the next item in the set.
Unlike https://(), this function never causes https:// 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 set.
This function was introduced in Qt 5.7.
See Also▲
See also https://(), https://()
[since 4.2] QSet::iterator QSet::erase(QSet::iterator pos)▲
This is an overloaded function.
This function was introduced in Qt 4.2.
[since 4.2] QSet::const_iterator QSet::find(const T &value) const▲
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the function returns https://().
This function was introduced in Qt 4.2.
See Also▲
See also https://(), https://()
[since 4.2] QSet::iterator QSet::find(const T &value)▲
This is an overloaded function.
Returns a non-const iterator positioned at the item value in the set. If the set contains no item value, the function returns https://().
This function was introduced in Qt 4.2.
[static] QSet<T> QSet::fromList(const QList<T> &list)▲
Returns a new https:// object containing the data contained in list. Since https:// doesn't allow duplicates, the resulting https:// might be smaller than the list, because https:// can contain duplicates.
Example:
QStringList list;
list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia";
QSet<QString> set = QSet<QString>::fromList(list);
set.contains("Julia"); // returns true
set.contains("Mike"); // returns true
set.size(); // returns 2Since Qt 5.14, range constructors are available for Qt's generic https:// and should be used in place of this method.
See Also▲
See also https://(), QList::toSet()
QSet::iterator QSet::insert(const T &value)▲
Inserts item value into the set, if value isn't already in the set, and returns an iterator pointing at the inserted item.
See Also▲
See also https://(), https://(), https://()
QSet<T> &QSet::intersect(const QSet<T> &other)▲
Removes all items from this set that are not contained in the other set. A reference to this set is returned.
See Also▲
See also https://(), https://(), https://(), https://()
[since 5.6] bool QSet::intersects(const QSet<T> &other) const▲
Returns true if this set has at least one item in common with other.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://()
bool QSet::isEmpty() const▲
Returns true if the set contains no elements; otherwise returns false.
See Also▲
See also https://()
[since 5.6] QSet::reverse_iterator QSet::rbegin()▲
Returns a https:// reverse iterator pointing to the first item in the set, in reverse order.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://()
[since 5.6] QSet::const_reverse_iterator QSet::rbegin() const▲
This is an overloaded function.
This function was introduced in Qt 5.6.
bool QSet::remove(const T &value)▲
Removes any occurrence of item value from the set. Returns true if an item was actually removed; otherwise returns false.
See Also▲
See also https://(), https://()
[since 5.6] QSet::reverse_iterator QSet::rend()▲
Returns a https:// reverse iterator pointing to one past the last item in the set, in reverse order.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://(), https://()
[since 5.6] QSet::const_reverse_iterator QSet::rend() const▲
This is an overloaded function.
This function was introduced in Qt 5.6.
void QSet::reserve(int size)▲
Ensures that the set's internal hash table consists of at least size buckets.
This function is useful for code that needs to build a huge set and wants to avoid repeated reallocation. For example:
QSet<QString> set;
set.reserve(20000);
for (int i = 0; i < 20000; ++i)
set.insert(values[i]);Ideally, size should be slightly more than the maximum number of elements expected in the set. size doesn't have to be prime, because https:// will use a prime number internally anyway. If size is an underestimate, the worst that will happen is that the https:// will be a bit slower.
In general, you will rarely ever need to call this function. https://'s internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.
See Also▲
See also https://(), https://()
int QSet::size() const▲
void QSet::squeeze()▲
Reduces the size of the set's internal hash table to save memory.
The sole purpose of this function is to provide a means of fine tuning https://'s memory usage. In general, you will rarely ever need to call this function.
See Also▲
See also https://(), https://()
QSet<T> &QSet::subtract(const QSet<T> &other)▲
Removes all items from this set that are contained in the other set. Returns a reference to this set.
See Also▲
See also https://(), https://(), https://()
void QSet::swap(QSet<T> &other)▲
Swaps set other with this set. This operation is very fast and never fails.
QList<T> QSet::toList() const▲
Returns a new https:// containing the elements in the set. The order of the elements in the https:// is undefined.
Example:
QSet<QString> set;
set << "red" << "green" << "blue" << ... << "black";
QList<QString> list = set.toList();
std::sort(list.begin(), list.end());Since Qt 5.14, range constructors are available for Qt's generic https:// and should be used in place of this method.
See Also▲
See also https://(), QList::fromSet()
QSet<T> &QSet::unite(const QSet<T> &other)▲
Each item in the other set that isn't already in this set is inserted into this set. A reference to this set is returned.
See Also▲
See also https://(), https://(), https://()
QList<T> QSet::values() const▲
Returns a new https:// containing the elements in the set. The order of the elements in the https:// is undefined.
This is the same as https://().
Since Qt 5.14, range constructors are available for Qt's generic https:// and should be used in place of this method.
See Also▲
See also https://(), QList::fromSet()
bool QSet::operator!=(const QSet<T> &other) const▲
Returns true if the other set is not equal to this set; otherwise returns false.
Two sets are considered equal if they contain the same elements.
This function requires the value type to implement operator==().
See Also▲
See also https://()
QSet<T> QSet::operator&(const QSet<T> &other) const▲
Returns a new https:// that is the intersection of this set and the other set.
See Also▲
See also https://(), https://(), https://(), https://()
QSet<T> &QSet::operator&=(const QSet<T> &other)▲
QSet<T> &QSet::operator&=(const T &value)▲
This is an overloaded function.
Same as intersect(other), if we consider other to be a set that contains the singleton value.
QSet<T> QSet::operator-(const QSet<T> &other) const▲
Returns a new https:// that is the set difference of this set and the other set, i.e., this set - other set.
See Also▲
See also https://(), https://(), https://(), https://()
QSet<T> &QSet::operator-=(const QSet<T> &other)▲
QSet<T> &QSet::operator-=(const T &value)▲
Removes the occurrence of item value from the set, if it is found, and returns a reference to the set. If the value is not contained the set, nothing is removed.
See Also▲
See also https://()
bool QSet::operator==(const QSet<T> &other) const▲
Returns true if the other set is equal to this set; otherwise returns false.
Two sets are considered equal if they contain the same elements.
This function requires the value type to implement operator==().
See Also▲
See also https://()
Related Non-Members▲
QDataStream &operator<<(QDataStream &out, const QSet<T> &set)▲
Writes the set to stream out.
This function requires the value type to implement operator<<().
See Also▲
See also https://
QDataStream &operator>>(QDataStream &in, QSet<T> &set)▲
Reads a set from stream in into set.
This function requires the value type to implement operator>>().
See Also▲
See also https://


