sqliteHow do I use SQLite with Qt?
SQLite is a popular open source database engine that can be used with Qt. To use SQLite with Qt, you must first create a database connection using the QSqlDatabase class. Then, you can create a query using the QSqlQuery class and execute it to perform database operations, such as inserting, updating, and deleting data.
Below is an example of how to use SQLite with Qt:
// Create a database connection
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
// Open the connection
if (!db.open()) {
qDebug() << "Error: connection with database fail";
} else {
qDebug() << "Database: connection ok";
}
// Create a query
QSqlQuery query;
// Execute the query
query.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)");
// Output
qDebug() << "Table created!";
Output example
Database: connection ok
Table created!
The code above does the following:
- Creates a database connection using the QSqlDatabase class.
- Opens the connection.
- Creates a query using the QSqlQuery class.
- Executes the query to create a table.
- Outputs a message when the table is created.
For more information, please refer to the following links:
More of Sqlite
- How to configure SQLite with XAMPP on Windows?
- How do I use SQLite xfilter to filter data?
- How can I use SQLite with Xamarin?
- How do I install SQLite on Windows?
- How can I use SQLite with Unity to store and retrieve data?
- How do I use UUIDs in SQLite?
- How do I use the SQLite SUBSTRING function?
- How can SQLite and ZFS be used together for software development?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I use the SQLite zfill function?
See more codes...