QPersistentModelIndex Class
QPersistentModelIndex 类用于定位数据模型中的数据。更多
Header: | #include <QPersistentModelIndex> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 所有成员(包括继承成员)的列表
- QPersistentModelIndex 属于隐式共享类。
该类具有很强的可比性。
该类与QModelIndex 具有很强的可比性。
公共函数
QPersistentModelIndex(const QModelIndex &index) | |
QPersistentModelIndex(const QPersistentModelIndex &other) | |
QPersistentModelIndex(QPersistentModelIndex &&other) | |
int | column() const |
QVariant | data(int role = Qt::DisplayRole) const |
Qt::ItemFlags | flags() const |
bool | isValid() const |
const QAbstractItemModel * | model() const |
(since 6.0) void | multiData(QModelRoleDataSpan roleDataSpan) const |
QModelIndex | parent() const |
int | row() const |
QModelIndex | sibling(int row, int column) const |
void | swap(QPersistentModelIndex &other) |
QModelIndex | operator QModelIndex() const |
QPersistentModelIndex & | operator=(QPersistentModelIndex &&other) |
QPersistentModelIndex & | operator=(const QModelIndex &other) |
QPersistentModelIndex & | operator=(const QPersistentModelIndex &other) |
相关非成员
size_t | qHash(const QPersistentModelIndex &key, size_t seed = 0) |
bool | operator!=(const QPersistentModelIndex &lhs, const QModelIndex &rhs) |
bool | operator!=(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) |
bool | operator<(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) |
bool | operator==(const QPersistentModelIndex &lhs, const QModelIndex &rhs) |
bool | operator==(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) |
详细描述
QPersistentModelIndex 是一种模型索引,应用程序可将其存储起来,之后再用来访问模型中的信息。与QModelIndex 类不同的是,存储 QPersistentModelIndex 是安全的,因为只要模型可以访问项,模型就会确保对项的引用继续有效。
在使用持久化模型索引之前,最好先检查它们是否有效。
注意: 不能将QStandardItemModel 的 QPersistentModelIndex 存储在模型的某个项中。
另请参阅 模型/视图编程、QModelIndex 和QAbstractItemModel 。
成员函数文档
QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index)
创建一个新的 QPersistentModelIndex,它是模型index 的副本。
QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other)
创建一个新的 QPersistentModelIndex,它是other 持久模型索引的副本。
[noexcept]
QPersistentModelIndex::QPersistentModelIndex(QPersistentModelIndex &&other)
移动-构建一个 QPersistentModelIndex 实例,使其指向other 所指向的同一对象。
int QPersistentModelIndex::column() const
返回此持久性模型索引指向的列。
QVariant QPersistentModelIndex::data(int role = Qt::DisplayRole) const
返回给定role 索引所指向项目的数据,如果该持久性模型索引是invalid ,则返回默认构建的QVariant 。
另请参阅 Qt::ItemDataRole 和QAbstractItemModel::setData()。
Qt::ItemFlags QPersistentModelIndex::flags() const
返回索引所指项目的标志。
bool QPersistentModelIndex::isValid() const
如果该持久模型索引有效,则返回true
;否则返回false
。
一个有效的索引属于一个模型,并且行数和列数都不是负数。
const QAbstractItemModel *QPersistentModelIndex::model() const
返回索引所属的模型。
[since 6.0]
void QPersistentModelIndex::multiData(QModelRoleDataSpan roleDataSpan) const
为索引指向的项目填充给定的roleDataSpan 。
此函数在 Qt 6.0 中引入。
另请参阅 Qt::ItemDataRole 和QAbstractItemModel::setData()。
QModelIndex QPersistentModelIndex::parent() const
返回该持久性索引的父QModelIndex ,如果没有父索引,则返回无效的QModelIndex 。
int QPersistentModelIndex::row() const
返回此持久性模型索引指向的行。
QModelIndex QPersistentModelIndex::sibling(int row, int column) const
返回row 和column 的同级程序,如果该位置没有同级程序,则返回无效的QModelIndex 。
另请参见 parent()。
[noexcept]
void QPersistentModelIndex::swap(QPersistentModelIndex &other)
将此持久性 modelindex 与other 互换。该操作速度非常快,从未出现过故障。
QModelIndex QPersistentModelIndex::operator QModelIndex() const
投递运算符,返回QModelIndex 。
[noexcept]
QPersistentModelIndex &QPersistentModelIndex::operator=(QPersistentModelIndex &&other)
Move-assignsother 到此QPersistentModelIndex 实例。
QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other)
设置持久模型索引,使其指向模型中与other 模型索引相同的项目。
QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIndex &other)
设置持久性模型索引,使其指向模型中与other 持久性模型索引相同的项目。
相关非成员
[noexcept]
size_t qHash(const QPersistentModelIndex &key, size_t seed = 0)
返回key 的哈希值,使用seed 作为计算的种子。
[noexcept]
bool operator!=(const QPersistentModelIndex &lhs, const QModelIndex &rhs)
如果lhs 持久模型索引与rhs 模型索引指向的位置不同,则返回true
;否则返回false
。
[noexcept]
bool operator!=(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs)
如果lhs 持久模型索引不等于rhs 持久模型索引,则返回true
;否则返回false
。
[noexcept]
bool operator<(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs)
如果lhs 持久模型索引小于rhs 持久模型索引,则返回true
;否则返回false
。
在与另一个持久性模型索引比较时,将使用持久性模型索引中的内部数据指针、行、列和模型值。
[noexcept]
bool operator==(const QPersistentModelIndex &lhs, const QModelIndex &rhs)
如果lhs 持久模型索引指向的位置与rhs 模型索引指向的位置相同,则返回true
;否则返回false
。
在与另一个模型索引比较时,将使用持久模型索引中的内部数据指针、行、列和模型值。
[noexcept]
bool operator==(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs)
如果lhs 持久模型索引等于rhs 持久模型索引,则返回true
;否则返回false
。
在与另一个持久性模型索引比较时,将使用持久性模型索引中的内部数据指针、行、列和模型值。
© 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.