QSqlRelation Class

QSqlRelation 类存储有关 SQL 外键的信息。更多

头文件: #include <QSqlRelation>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sql)
target_link_libraries(mytarget PRIVATE Qt6::Sql)
qmake: QT += sql

公共函数

QSqlRelation()
QSqlRelation(const QString &tableName, const QString &indexColumn, const QString &displayColumn)
QString displayColumn() const
QString indexColumn() const
bool isValid() const
void swap(QSqlRelation &other)
QString tableName() const

详细说明

QSqlRelation 是QSqlRelationalTableModel 的一个辅助类。详见QSqlRelationalTableModel::setRelation() 和QSqlRelationalTableModel::relation() 。

另请参阅 QSqlRelationalTableModel,QSqlRelationalDelegate关系表模型示例

成员函数文档

QSqlRelation::QSqlRelation()

构造一个无效的 QSqlRelation 对象。

对于这样的对象,tableName(),indexColumn() 和displayColumn() 函数将返回空字符串。

另请参阅 isValid()。

QSqlRelation::QSqlRelation(const QString &tableName, const QString &indexColumn, const QString &displayColumn)

构造一个 QSqlRelation 对象,其中tableName 是外键指向的 SQL 表名,indexColumn 是外键,displayColumn 是应显示给用户的字段。

另请参阅 tableName()、indexColumn() 和displayColumn()。

QString QSqlRelation::displayColumn() const

返回表tableName() 中应显示给用户而不是外键的列。

QString QSqlRelation::indexColumn() const

从表tableName() 返回外键指向的索引列。

[noexcept] bool QSqlRelation::isValid() const

如果QSqlRelation 对象有效,则返回true ;否则返回false

[noexcept] void QSqlRelation::swap(QSqlRelation &other)

将此关系与other 互换。这一操作速度非常快,而且从未出现过故障。

QString QSqlRelation::tableName() const

返回外键指向的表的名称。

© 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.