So far, we have been running queries, but not getting any data in return. One of the points of a database is to query for data, not just to enter it. What fun would it be if we could only input data? The Qt API has a way to accommodate the different syntax and millions of ways a query can be made. Most of the time, it is specific to the type of data you need to be returned, but also specific to the database data itself. Luckily, QSqlQuery
is general enough that the query parameter is a string.
To retrieve data, execute a query using QsqlQuery
and then operate on the records using the following functions:
first()
last()
next()
previous()
seek(int)
The first()
and last()
functions will retrieve the first and last records respectively. To iterate backward through the records, use previous()
. The seek (int)
function takes on integer as an argument to determine which record to retrieve.
We will usenext()
, which will iterate forward through the records found in the query:
QSqlDatabasedb...