QMetaSequence Class
QMetaSequence 类允许对顺序容器进行类型擦除访问。更多
Header: | #include <QMetaSequence> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
自 | Qt 6.0 |
继承: | QMetaContainer |
该类具有等价可比性。
公共函数
void | addValue(void *container, const void *value) const |
void | addValueAtBegin(void *container, const void *value) const |
void | addValueAtEnd(void *container, const void *value) const |
bool | canAddValue() const |
bool | canAddValueAtBegin() const |
bool | canAddValueAtEnd() const |
bool | canEraseRangeAtIterator() const |
bool | canEraseValueAtIterator() const |
bool | canGetValueAtConstIterator() const |
bool | canGetValueAtIndex() const |
bool | canGetValueAtIterator() const |
bool | canInsertValueAtIterator() const |
bool | canRemoveValue() const |
bool | canRemoveValueAtBegin() const |
bool | canRemoveValueAtEnd() const |
bool | canSetValueAtIndex() const |
bool | canSetValueAtIterator() const |
void | eraseRangeAtIterator(void *container, const void *iterator1, const void *iterator2) const |
void | eraseValueAtIterator(void *container, const void *iterator) const |
void | insertValueAtIterator(void *container, const void *iterator, const void *value) const |
bool | isSortable() const |
void | removeValue(void *container) const |
void | removeValueAtBegin(void *container) const |
void | removeValueAtEnd(void *container) const |
void | setValueAtIndex(void *container, qsizetype index, const void *value) const |
void | setValueAtIterator(const void *iterator, const void *value) const |
void | valueAtConstIterator(const void *iterator, void *result) const |
void | valueAtIndex(const void *container, qsizetype index, void *result) const |
void | valueAtIterator(const void *iterator, void *result) const |
QMetaType | valueMetaType() const |
静态公共成员
(since 6.0) QMetaSequence | fromContainer() |
相关非成员
(since 6.0) bool | operator!=(const QMetaSequence &lhs, const QMetaSequence &rhs) |
(since 6.0) bool | operator==(const QMetaSequence &lhs, const QMetaSequence &rhs) |
详细描述
该类使用 void* 作为操作数,提供了许多原始的容器操作。这样,您就可以在不知道变量类型的情况下操作从变量中获取的通用容器。
各种方法的 void* 参数通常是通过使用相应容器或值类型的QVariant 并调用其QVariant::data() 或QVariant::constData() 方法创建的。不过,也可以传递指向容器或值类型对象的普通指针。
迭代器失效遵循底层容器给出的规则,而不是在 API 中表达。因此,对于真正的通用容器来说,任何写入操作后的迭代器都应视为无效。
成员函数文档
void QMetaSequence::addValue(void *container, const void *value) const
如果可能,将value 添加到container 。如果canAddValue() 返回false
,则不添加value 。否则,如果canAddValueAtEnd() 返回true
,则value 会添加到container 的末尾。否则,如果canAddValueAtBegin() 返回true
,则value 会添加到容器的开头。否则,该值将添加到未指定的位置或根本不添加。将值添加到无序容器的情况属于后者,例如QSet 。
另请参阅 canAddValue()、canAddValueAtBegin()、canAddValueAtEnd()、isSortable() 和removeValue()。
void QMetaSequence::addValueAtBegin(void *container, const void *value) const
如果可能,将value 添加到container 的开头。如果canAddValueAtBegin() 返回false
,则不添加value 。
另请参阅 canAddValueAtBegin()、isSortable() 和removeValueAtBegin()。
void QMetaSequence::addValueAtEnd(void *container, const void *value) const
如果可能,将value 添加到container 的末尾。如果canAddValueAtEnd() 返回false
,则不添加value 。
另请参阅 canAddValueAtEnd()、isSortable() 和removeValueAtEnd()。
bool QMetaSequence::canAddValue() const
如果值可以添加到容器中,则返回true
,否则返回false
。
另请参阅 addValue() 和isSortable() 。
bool QMetaSequence::canAddValueAtBegin() const
如果使用addValue() 添加的值可以放在容器的开头,则返回true
,否则返回false
。
另请参见 addValueAtBegin() 和canAddValueAtEnd()。
bool QMetaSequence::canAddValueAtEnd() const
如果使用addValue() 添加的值可以放在容器末尾,则返回true
,否则返回false
。
另请参阅 addValueAtEnd() 和canAddValueAtBegin()。
bool QMetaSequence::canEraseRangeAtIterator() const
如果两个迭代器之间的范围可以从容器中删除,则返回true
,否则返回false
。
bool QMetaSequence::canEraseValueAtIterator() const
如果非const迭代器指向的值可以被擦除,则返回true
,否则返回false
。
另请参阅 hasIterator() 和eraseValueAtIterator() 。
bool QMetaSequence::canGetValueAtConstIterator() const
如果底层容器可以检索常量迭代器指向的值,则返回true
,否则返回false
。
另请参阅 hasConstIterator() 和valueAtConstIterator() 。
bool QMetaSequence::canGetValueAtIndex() const
如果可以通过索引从容器中获取值,则返回true
,否则返回false
。
另请参阅 valueAtIndex() 。
bool QMetaSequence::canGetValueAtIterator() const
如果底层容器可以检索非const迭代器指向的值,则返回true
,否则返回false
。
另请参阅 hasIterator() 和valueAtIterator() 。
bool QMetaSequence::canInsertValueAtIterator() const
如果底层容器可以插入新值,则返回true
,同时考虑到非const迭代器指向的位置。
另请参阅 hasIterator() 和insertValueAtIterator() 。
bool QMetaSequence::canRemoveValue() const
如果值可以从容器中移除,则返回true
,否则返回false
。
另请参阅 removeValue() 和isSortable() 。
bool QMetaSequence::canRemoveValueAtBegin() const
如果可以使用removeValue() 从容器开头移除值,则返回true
,否则返回false
。
另请参见 removeValueAtBegin() 和canRemoveValueAtEnd()。
bool QMetaSequence::canRemoveValueAtEnd() const
如果可以使用removeValue() 从容器末尾移除值,则返回true
,否则返回false
。
另请参见 removeValueAtEnd() 和canRemoveValueAtBegin()。
bool QMetaSequence::canSetValueAtIndex() const
如果可以按索引将值写入容器,则返回true
,否则返回false
。
另请参阅 setValueAtIndex() 。
bool QMetaSequence::canSetValueAtIterator() const
如果底层容器可以写入非const迭代器指向的值,则返回true
,否则返回false
。
另请参阅 hasIterator() 和setValueAtIterator() 。
void QMetaSequence::eraseRangeAtIterator(void *container, const void *iterator1, const void *iterator2) const
如果可能,从container 中删除迭代器iterator1 和iterator2 之间的数值范围。
另请参阅 canEraseValueAtIterator()、begin() 和end()。
void QMetaSequence::eraseValueAtIterator(void *container, const void *iterator) const
如果可能,从container 中擦除非 constiterator 指向的值。
另请参阅 canEraseValueAtIterator()、begin() 和end()。
[static constexpr, since 6.0]
template <typename T> QMetaSequence QMetaSequence::fromContainer()
返回与作为模板参数给定的类型相对应的QMetaSequence 。
此函数在 Qt 6.0 中引入。
void QMetaSequence::insertValueAtIterator(void *container, const void *iterator, const void *value) const
在可能的情况下,将value 插入container ,同时考虑非 Constiterator 。如果canInsertValueAtIterator() 返回false
,则不插入value 。否则,如果isSortable() 返回true
,则在iterator 指向的值之前插入该值。否则,将在未指定的位置插入value 或根本不插入。在后一种情况下,iterator 将作为一个提示。如果它指向value 的正确位置,操作速度可能比不使用迭代器的addValue() 更快。
另请参见 canInsertValueAtIterator()、isSortable()、begin() 和end()。
bool QMetaSequence::isSortable() const
如果底层容器可排序,则返回true
,否则返回false
。如果添加到容器中的值被放置在定义的位置,则认为容器是可排序的。向可排序容器插入或添加值总是会成功。向不可排序的容器中插入或添加值可能不会成功,例如,如果容器是一个QSet ,其中已经包含了要插入的值。
另请参阅 addValue()、insertValueAtIterator()、canAddValueAtBegin()、canAddValueAtEnd()、canRemoveValueAtBegin() 和canRemoveValueAtEnd()。
void QMetaSequence::removeValue(void *container) const
如果可能,从container 中删除一个值。如果canRemoveValue() 返回false
,则不删除任何值。否则,如果canRemoveValueAtEnd() 返回true
,则删除container 中的最后一个值。否则,如果canRemoveValueAtBegin() 返回true
,则删除container 中的第一个值。否则,将删除一个未指定的值或什么都不删除。
另请参阅 canRemoveValue()、canRemoveValueAtBegin()、canRemoveValueAtEnd()、isSortable() 和addValue()。
void QMetaSequence::removeValueAtBegin(void *container) const
如果可能,从container 开头移除一个值。如果canRemoveValueAtBegin() 返回false
,则不删除该值。
另请参阅 canRemoveValueAtBegin()、isSortable() 和addValueAtBegin()。
void QMetaSequence::removeValueAtEnd(void *container) const
如果可能,从container 结尾移除一个值。如果canRemoveValueAtEnd() 返回false
,则不会删除该值。
另请参阅 canRemoveValueAtEnd()、isSortable() 和addValueAtEnd()。
void QMetaSequence::setValueAtIndex(void *container, qsizetype index, const void *value) const
如果可能,使用作为参数传递的value 在container 中覆盖index 的值。
另请参阅 valueAtIndex() 和canSetValueAtIndex()。
void QMetaSequence::setValueAtIterator(const void *iterator, const void *value) const
如果可能,将value 写入非常数iterator 指向的值。
另请参阅 valueAtIterator()、canSetValueAtIterator()、begin() 和end()。
void QMetaSequence::valueAtConstIterator(const void *iterator, void *result) const
读取常量iterator 指向的值,并尽可能将其存储到result 指向的内存位置。
另请参见 canGetValueAtConstIterator()、constBegin() 和constEnd()。
void QMetaSequence::valueAtIndex(const void *container, qsizetype index, void *result) const
读取container 中index 的值,并将其放入result 所指向的内存位置(如果可能的话)。
另请参阅 setValueAtIndex() 和canGetValueAtIndex()。
void QMetaSequence::valueAtIterator(const void *iterator, void *result) const
读取非constiterator 指向的值,并尽可能将其存储到result 指向的内存位置。
另请参见 setValueAtIterator()、canGetValueAtIterator()、begin() 和end()。
QMetaType QMetaSequence::valueMetaType() const
返回容器中存储值的元类型。
相关非成员
[noexcept, since 6.0]
bool operator!=(const QMetaSequence &lhs, const QMetaSequence &rhs)
如果QMetaSequence lhs 表示与QMetaSequence rhs 不同的容器类型,则返回true
,否则返回false
。
此函数在 Qt 6.0 中引入。
[noexcept, since 6.0]
bool operator==(const QMetaSequence &lhs, const QMetaSequence &rhs)
如果QMetaSequence lhs 表示与QMetaSequence rhs 相同的容器类型,则返回true
,否则返回false
。
此函数在 Qt 6.0 中引入。
© 2025 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.