Get the App
SLTechnology News&Howtos  ›  Database  › 

An example of QT accessing QSqlite database

Shulou Source: shulou.com Published: 2022-06-01 08:49:19 10月24日 Update

The QtSql module provides an interface to access the SQL database independent of the platform and database type, which is supported by a set of classes that integrate the database and the user interface using the model view structure of Qt.

The QSqlDatabase object symbolizes the association of the database. Qt uses drivers to communicate with the API of various databases. The desktop version of Qt (Desktop Edition) includes the following drivers:

Driver database

QDB2 IBM DB2 version 7.1 and newer version

QIBASE Borland InterBase

QMYSQL MySql

QOCI Oracle (Oracle Call Interface)

QODBC ODBC (including Microsoft's QSL service)

Version 7.3 and later of QPSQL PostgreSQL

QSQLITE QSLite version 3

QSQLITE2 QSLite version 2

QTDS Qybase adaptive server

Access to an example of QSqlite database: step: 1. Create a Qt console program. 2. Add QT + = sql;3 to the pro inquiry and the following code to the main.cpp:

[cpp] view plain copy print?

# include

# include

# include

# include

# include

# include

# include

# include

# include

Int main (int argc, char * argv [])

{

QCoreApplication a (argc, argv)

QSqlDatabase database = QSqlDatabase::addDatabase ("QSQLITE")

Database.setDatabaseName ("CashSystem.db")

If (database.open ())

{

QDebug ()

Tags: Data database program interface driver driver success file version Nanchong service instance code company object tool platform screenshot console datasheet Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei vpn Shulou Technology macOS