Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
Selecting data from a database without using SQL statements in Qt
This example shows how to select data with QSqlTableModel from an SQLite database in Qt without using any SQL statements.
The table 'person' has the following columns:
- id (integer primary key), this is an auto-increment field
- firstname (varchar(20))
- lastname (varchar(30))
- age (integer)
Download and install the Qt SDK
For Maemo SQLite development, the following packages must be installed:
Select person data. The person ID is given as a filter for the selection.
QString MyWidget::searchPersonName(int personId)
QSqlTableModel *model = new QSqlTableModel;
// Set used table
// Set where clause
//The index of the record we are interested in
int index = 0;
// Read result
QSqlRecord record = model->record(index);
name = record.value(2).toString();
The person's data is selected from the database without using SQL statements.