6.0.0-rc4Source

QSqlRelation Class

The QSqlRelation class stores information about an SQL foreign key. More…

Header#include <QSqlRelation>
CMaketarget_link_libraries(app PRIVATE Nt::Sql)
ModuleNt SQL C++ Classes

List of all members, including inherited members

Public Functions

QSqlRelation()
QSqlRelation(const QString &tableName, const QString &indexColumn, const QString &displayColumn)
voidswap(QSqlRelation &other)
QStringtableName() const
QStringindexColumn() const
QStringdisplayColumn() const
boolisValid() 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.