QSqlRelation Class
The QSqlRelation class stores information about an SQL foreign key. More…
| Header | #include <QSqlRelation> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Sql) |
| Module | Nt SQL C++ Classes |
List of all members, including inherited members
Public Functions
| QSqlRelation() | |
| QSqlRelation(const QString &tableName, const QString &indexColumn, const QString &displayColumn) | |
| void | swap(QSqlRelation &other) |
| QString | tableName() const |
| QString | indexColumn() const |
| QString | displayColumn() const |
| bool | isValid() const |
Detailed Description
A QSqlRelation tells QSqlRelationalTableModel::setRelation() what a foreign key column refers to: the table, the column of that table whose values the key holds, and the column of that table that is shown to the user instead.
// employee.city holds a value of city.id, and is shown as city.name
model.setRelation(2, QSqlRelation("city", "id", "name"));
See also QSqlRelationalTableModel.
Differences from Qt
None.
Member Function Documentation
QSqlRelation::QSqlRelation()
Constructs an invalid relation, which stands for no relation.
See also isValid().
QSqlRelation::QSqlRelation(const QString &tableName, const QString &indexColumn, const QString &displayColumn)
Constructs a relation to the table tableName: a foreign key holds a value of the column indexColumn of that table, and is shown as the value that the column displayColumn has in the same row.
QString QSqlRelation::displayColumn() const
Returns the name of the column of tableName() that is shown in the place of the foreign key.
QString QSqlRelation::indexColumn() const
Returns the name of the column of tableName() that the foreign key holds a value of.
bool QSqlRelation::isValid() const
Returns true if the relation has a table, an index column and a display column; otherwise returns false.
void QSqlRelation::swap(QSqlRelation &other)
Swaps this relation with other.
QString QSqlRelation::tableName() const
Returns the name of the table that the foreign key refers to.