You can work with SQL queries in Qt and SQL in many different ways, here I will show you how I came up with a working method. To keep things simple, I am not going to use any UI to print or edit queries. It will be just source code and stdout, as a database engine I will use SQLite3.
After you created your project, edit project.pro and locate line:
QT += core
Modify this line by adding `sql`:
QT += core sql
Since now, when you compile your project, QtSql module will be linked to the project: