This tutorial will show you how to use SQLite and Qt SQL to have a relational database in your application. It will cover all the basic operations needed to work with a database like creating a table, inserting data, executing a query and checking the results. Full project and source code are provided.
SQLite and Qt SQL
This tutorial is based on two main components: Qt SQL and SQLite.
The Qt SQL module provides a driver layer, SQL API layer, and a user interface layer for SQL databases.
SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. Basically a database stored in a single file (or memory).
Qt offers support (drivers) for other popular databases like MySQL and
Very simple and helpful.
Is it possible to get result value of a column in current row using its name?
Thank you.
yes, you can pass a QString to QSqlQuery::value().
This is less efficient than passing an index as showed in the tutorial though,
why can’t i use mInputText? it seems there is something missing the compiler doesn’t know it.
have you downloaded my source code?
What error are you getting?
Shouldn’t “qWarning() << "ERROR: " << db.lastError();" be "qWarning() << "ERROR: " << db.lastError().text;" ?
Very Helpful !!
Thanks a lot
maybe something I get wrong…
I use Visual Studio 2015, create a Qt (5.11.1) Gui project and cut and paste you main.cpp, mainwindow.cpp/h file, built project and run it
but the mInputText is a inactive editor box, so I can not enter anything to search…
What I get wrong…
Not useful if using meory databse. How do we create a database that lives past the application life time? You know the very reason to use a db in the first place. How do we put it in a directory that makes sense.