QMetaSequence Class
QMetaSequence 类支持以类型擦除的方式访问顺序容器。更多内容...
| 头文件: | #include <QMetaSequence> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 自: | Qt 6.0 |
| 继承自: | QMetaContainer |
QMetaSequence 比较
| 类别 | 可比较类型 |
|---|---|
| 相等性 | QMetaSequence |
公共类型
(since 6.11) class | Iterable |
公共函数
| QMetaSequence() | |
| 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* 为操作数的原始容器操作。通过这种方式,您可以在无需了解其类型的情况下,对从 Variant 中获取的泛型容器进行操作。
各种方法的 `void*` 参数通常是通过使用相应容器或值类型的 `QVariant `,并调用其 `QVariant::data()` 或 `QVariant::constData()` 方法来创建的。不过,您也可以直接传递指向该容器或值类型对象的普通指针。
迭代器的失效遵循底层容器规定的规则,且未在API中明确说明。因此,对于真正的泛型容器,在任何写入操作之后,所有迭代器都应被视为无效。
成员函数文档
[constexpr noexcept default] QMetaSequence::QMetaSequence()
默认——构造一个QMetaSequence 实例。
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
如果非常量迭代器所指向的值可以被擦除,则返回 `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
如果底层容器可以在考虑非const迭代器所指向的位置的情况下插入新值,则返回true 。
另请参阅 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
如果可能,将非const类型的iterator 所指向的值从container 中清除。
另请参阅 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 中,同时考虑非const的iterator 。如果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 写入由非const变量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
若条件允许,则获取非const类型的iterator 所指向的值,并将其存储到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 中引入。
© 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.