QMetaAssociation Class

The QMetaAssociation class allows type erased access to associative containers. 更多...

头: #include <QMetaAssociation>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 6.0
继承: QMetaContainer

此类 相等可比较 .

公共函数

bool canContainsKey () const
bool canCreateConstIteratorAtKey () const
bool canCreateIteratorAtKey () const
bool canGetKeyAtConstIterator () const
bool canGetKeyAtIterator () const
bool canGetMappedAtConstIterator () const
bool canGetMappedAtIterator () const
bool canGetMappedAtKey () const
bool canInsertKey () const
bool canRemoveKey () const
bool canSetMappedAtIterator () const
bool canSetMappedAtKey () const
bool containsKey (const void * container , const void * key ) const
void * createConstIteratorAtKey (const void * container , const void * key ) const
void * createIteratorAtKey (void * container , const void * key ) const
void insertKey (void * container , const void * key ) const
void keyAtConstIterator (const void * iterator , void * key ) const
void keyAtIterator (const void * iterator , void * key ) const
QMetaType keyMetaType () const
void mappedAtConstIterator (const void * iterator , void * mapped ) const
void mappedAtIterator (const void * iterator , void * mapped ) const
void mappedAtKey (const void * container , const void * key , void * mapped ) const
QMetaType mappedMetaType () const
void removeKey (void * container , const void * key ) const
void setMappedAtIterator (const void * iterator , const void * mapped ) const
void setMappedAtKey (void * container , const void * key , const void * mapped ) const

静态公共成员

(从 6.0 起) QMetaAssociation fromContainer ()
bool operator!= (const QMetaAssociation & lhs , const QMetaAssociation & rhs )
bool operator== (const QMetaAssociation & lhs , const QMetaAssociation & rhs )

详细描述

The class provides a number of primitive container operations, using void* as operands. This way, you can manipulate a generic container retrieved from a Variant without knowing its type.

QMetaAssociation covers both, containers with mapped values such as QMap or QHash , and containers that only hold keys such as QSet .

The void* arguments to the various methods are typically created by using a QVariant of the respective container or value type, and calling its QVariant::data () 或 QVariant::constData () methods. However, you can also pass plain pointers to objects of the container or value type.

Iterator invalidation follows the rules given by the underlying containers and is not expressed in the API. Therefore, for a truly generic container, any iterators should be considered invalid after any write operation.

另请参阅 QMetaContainer , QMetaSequence , QIterable ,和 QIterator .

成员函数文档编制

bool QMetaAssociation:: canContainsKey () const

返回 true if the container can be queried for keys using containsKey (),否则返回 false .

bool QMetaAssociation:: canCreateConstIteratorAtKey () const

返回 true if a const iterator pointing to an entry in the container can be created using createConstIteratorAtKey (), otherwise returns false.

bool QMetaAssociation:: canCreateIteratorAtKey () const

返回 true if an iterator pointing to an entry in the container can be created using createIteratorAtKey (), otherwise returns false.

另请参阅 createIteratorAtKey ().

bool QMetaAssociation:: canGetKeyAtConstIterator () const

返回 true if a key can be retrieved from a const iterator using keyAtConstIterator (),否则返回 false .

另请参阅 keyAtConstIterator ().

bool QMetaAssociation:: canGetKeyAtIterator () const

返回 true if a key can be retrieved from a non-const iterator using keyAtIterator (),否则返回 false .

另请参阅 keyAtIterator ().

bool QMetaAssociation:: canGetMappedAtConstIterator () const

返回 true if a mapped value can be retrieved from a const iterator using mappedAtConstIterator (),否则返回 false .

另请参阅 mappedAtConstIterator ().

bool QMetaAssociation:: canGetMappedAtIterator () const

返回 true if a mapped value can be retrieved from a non-const iterator using mappedAtIterator (),否则返回 false .

另请参阅 mappedAtIterator ().

bool QMetaAssociation:: canGetMappedAtKey () const

返回 true if the container can be queried for values using mappedAtKey (),否则返回 false .

bool QMetaAssociation:: canInsertKey () const

返回 true if keys can be added to the container using insertKey (),否则返回 false .

另请参阅 insertKey ().

bool QMetaAssociation:: canRemoveKey () const

返回 true if keys can be removed from the container using removeKey (),否则返回 false .

另请参阅 removeKey ().

bool QMetaAssociation:: canSetMappedAtIterator () const

返回 true if a mapped value can be set via a non-const iterator using setMappedAtIterator (),否则返回 false .

另请参阅 setMappedAtIterator ().

bool QMetaAssociation:: canSetMappedAtKey () const

返回 true if mapped values can be modified in the container using setMappedAtKey (),否则返回 false .

另请参阅 setMappedAtKey ().

bool QMetaAssociation:: containsKey (const void * container , const void * key ) const

返回 truecontainer can be queried for keys and contains the key ,否则返回 false .

另请参阅 canContainsKey ().

void *QMetaAssociation:: createConstIteratorAtKey (const void * container , const void * key ) const

Returns a const iterator pointing to the entry of keycontainer , if possible. If the entry doesn't exist, creates a const iterator pointing to the end of the container . If no const iterator can be created, returns nullptr .

The const iterator has to be destroyed using destroyConstIterator ().

另请参阅 canCreateConstIteratorAtKey (), constBegin (), constEnd (),和 destroyConstIterator ().

void *QMetaAssociation:: createIteratorAtKey ( void * container , const void * key ) const

Returns a non-const iterator pointing to the entry of keycontainer , if possible. If the entry doesn't exist, creates a non-const iterator pointing to the end of the container . If no non-const iterator can be created, returns nullptr .

The non-const iterator has to be destroyed using destroyIterator ().

另请参阅 canCreateIteratorAtKey (), begin (), end (),和 destroyIterator ().

[static constexpr, since 6.0] template <typename T> QMetaAssociation QMetaAssociation:: fromContainer ()

返回 QMetaAssociation corresponding to the type given as template parameter.

该函数在 Qt 6.0 引入。

void QMetaAssociation:: insertKey ( void * container , const void * key ) const

插入 keycontainer if possible. If the container has mapped values a default-create mapped value is associated with the key .

另请参阅 canInsertKey ().

void QMetaAssociation:: keyAtConstIterator (const void * iterator , void * key ) const

Retrieves the key pointed to by the const iterator and stores it in the memory location pointed to by key , if possible.

另请参阅 canGetKeyAtConstIterator (), constBegin (), constEnd (),和 createConstIteratorAtKey ().

void QMetaAssociation:: keyAtIterator (const void * iterator , void * key ) const

Retrieves the key pointed to by the non-const iterator and stores it in the memory location pointed to by key , if possible.

另请参阅 canGetKeyAtIterator (), begin (), end (),和 createIteratorAtKey ().

QMetaType QMetaAssociation:: keyMetaType () const

Returns the meta type for keys in the container.

void QMetaAssociation:: mappedAtConstIterator (const void * iterator , void * mapped ) const

Retrieves the mapped value pointed to by the const iterator and stores it in the memory location pointed to by mapped , if possible.

另请参阅 canGetMappedAtConstIterator (), constBegin (), constEnd (),和 createConstIteratorAtKey ().

void QMetaAssociation:: mappedAtIterator (const void * iterator , void * mapped ) const

Retrieves the mapped value pointed to by the non-const iterator and stores it in the memory location pointed to by mapped , if possible.

另请参阅 setMappedAtIterator (), canGetMappedAtIterator (), begin (), end (),和 createIteratorAtKey ().

void QMetaAssociation:: mappedAtKey (const void * container , const void * key , void * mapped ) const

Retrieves the mapped value associated with the keycontainer and places it in the memory location pointed to by mapped , if that is possible.

另请参阅 setMappedAtKey () 和 canGetMappedAtKey ().

QMetaType QMetaAssociation:: mappedMetaType () const

Returns the meta type for mapped values in the container.

void QMetaAssociation:: removeKey ( void * container , const void * key ) const

移除 key and its associated mapped value from the container if possible.

另请参阅 canRemoveKey ().

void QMetaAssociation:: setMappedAtIterator (const void * iterator , const void * mapped ) const

写入 mapped value to the container location pointed to by the non-const iterator , if possible.

另请参阅 mappedAtIterator (), canSetMappedAtIterator (), begin (), end (),和 createIteratorAtKey ().

void QMetaAssociation:: setMappedAtKey ( void * container , const void * key , const void * mapped ) const

Overwrites the value associated with the keycontainer 使用 mapped value passed as argument if that is possible.

另请参阅 mappedAtKey () 和 canSetMappedAtKey ().

相关非成员

[noexcept] bool operator!= (const QMetaAssociation & lhs , const QMetaAssociation & rhs )

返回 true QMetaAssociation lhs represents a different container type than the QMetaAssociation rhs ,否则返回 false .

[noexcept] bool operator== (const QMetaAssociation & lhs , const QMetaAssociation & rhs )

返回 true QMetaAssociation lhs represents the same container type as the QMetaAssociation rhs ,否则返回 false .