本页内容

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

返回外键所引用的表的名称。

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