Is there a more expressive way of executing SQL query using Qt?
- by ShaChris23
I currently have this code:
// Construct query
QString const statement = QString("drop database if exists %1")
.arg(databaseName_);
QSqlQuery query(db);
query.exec(statement);
Is there a better way to code than the above?
Specifically, I dont like how I use QString for SQL statement. It'd be nice if Qt has some class so that I could do something like:
// Construct query
QSomeClass statement = "drop database if exists %1";
statement.setArg(1, databaseName_); // Replace all %1 in the original string.
QSqlQuery query(db);
query.exec(statement);