Doc: Fix QSql*Model snippets
- QSqlQueryModel docs contained a snippet about QSqlTableModel. - Snippet #25 was about QSqlTableModel, but it was previously unused. - This patch ensures that snippet code matches the corresponding text descriptions. Change-Id: I2a5ffbe0978ef9b8d0b027db59647b824e52d214 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
parent
78a6b80719
commit
520f7bb832
@ -249,16 +249,15 @@ void QSqlQueryModel_snippets()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! [21]
|
//! [21]
|
||||||
QSqlTableModel model;
|
QSqlQueryModel model;
|
||||||
model.setTable("employee");
|
model.setQuery("SELECT name, salary FROM employee");
|
||||||
model.select();
|
|
||||||
int salary = model.record(4).value("salary").toInt();
|
int salary = model.record(4).value("salary").toInt();
|
||||||
//! [21]
|
//! [21]
|
||||||
Q_UNUSED(salary);
|
Q_UNUSED(salary);
|
||||||
|
|
||||||
{
|
{
|
||||||
//! [22]
|
//! [22]
|
||||||
int salary = model.data(model.index(4, 2)).toInt();
|
int salary = model.data(model.index(4, 1)).toInt();
|
||||||
//! [22]
|
//! [22]
|
||||||
Q_UNUSED(salary);
|
Q_UNUSED(salary);
|
||||||
}
|
}
|
||||||
@ -308,7 +307,8 @@ void QSqlTableModel_snippets()
|
|||||||
//! [25]
|
//! [25]
|
||||||
QSqlTableModel model;
|
QSqlTableModel model;
|
||||||
model.setTable("employee");
|
model.setTable("employee");
|
||||||
QString name = model.record(4).value("name").toString();
|
model.select();
|
||||||
|
int salary = model.record(4).value("salary").toInt();
|
||||||
//! [25]
|
//! [25]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,8 @@ int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const
|
|||||||
\snippet sqldatabase/sqldatabase.cpp 21
|
\snippet sqldatabase/sqldatabase.cpp 21
|
||||||
|
|
||||||
The code snippet above extracts the \c salary field from record 4 in
|
The code snippet above extracts the \c salary field from record 4 in
|
||||||
the result set of the query \c{SELECT * from employee}. Assuming
|
the result set of the \c SELECT query. Since \c salary is the 2nd
|
||||||
that \c salary is column 2, we can rewrite the last line as follows:
|
column (or column index 1), we can rewrite the last line as follows:
|
||||||
|
|
||||||
\snippet sqldatabase/sqldatabase.cpp 22
|
\snippet sqldatabase/sqldatabase.cpp 22
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
|
|||||||
QSqlTableModel can also be used to access a database
|
QSqlTableModel can also be used to access a database
|
||||||
programmatically, without binding it to a view:
|
programmatically, without binding it to a view:
|
||||||
|
|
||||||
\snippet sqldatabase/sqldatabase.cpp 21
|
\snippet sqldatabase/sqldatabase.cpp 25
|
||||||
|
|
||||||
The code snippet above extracts the \c salary field from record 4 in
|
The code snippet above extracts the \c salary field from record 4 in
|
||||||
the result set of the query \c{SELECT * from employee}.
|
the result set of the query \c{SELECT * from employee}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user