There are variations on how you can do this, but the basics are:
1. define database
2. define query
Sqlite example:
// define database
db.setDatabaseName(dbName + ".sqlite");
db.open();
// define query
QSqlQuery query
(db
);
// db ties the query to the defined, open database query.exec("SELECT * from yourTable");
// define database
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", <yourConnectionName>);
db.setDatabaseName(dbName + ".sqlite");
db.open();
// define query
QSqlQuery query(db); // db ties the query to the defined, open database
query.exec("SELECT * from yourTable");
To copy to clipboard, switch view to plain text mode
If you split this code into two pieces then you can use the connectionName and don't have to re-define the database for each query.
Bookmarks