QmlSql Objects

QmlSQL is an essential module which provides support for SQL databases. Qt SQL's APIs are divided into different layers:

  • Driver layer
  • SQL API layer
  • User interface layer

The SQL Programming guide contains information about development using Qt SQL

Getting Started

To enable QmlSQL in a project, import it to the qml file you whish to use it in:


  import QmlSql 1.0

To link against the Qt SQL module, add this line to the project file:


  QT += sql

Below are the following objects that are available at this time for QmlSql.

QQmlSqlQuery

QmlSqlQuery class provides a means of executing and manipulating SQL statements

QmlSqlCreateDatabase

Creates a local database for sqlight only. One must set the databaseName and also the filePath in which they would like to save the database file. One can use a md5Sum that is randomly generated to create the databaseName. Or if you like you can also name the database fileName via databaseName. The method of is what is used to create the database

QmlSqlDatabase

Represents a connection to a database. The QmlSqlDatabase provides an interface for accessing a database through a connection. An instance of QmlSqlDatabase represents the connection. The connection provides access to the database via one of the supported , which are derived from . Alternatively, one can subclass your own database driver from . See How to Write Your Own Database Driver for more information. Create a connection (i.e., an instance of QSqlDatabase) by calling one of the method addDatabase() , where you specify the databaseDriver (i.e., what kind of database will you access) and a connectionName. A connection is known by its own name, Not by the name of the database it connects to. You can have multiple connections to one database. QSqlDatabase also supports the concept of a default connection (not recommended ), which is the unnamed connection. To create the default connection, don't pass the connection name argument before you call addDatabase(). Subsequently, when you call any method function that takes the connection name argument, if you don't pass the connectionName argument, the default connection is assumed. The following snippet shows how to create and open a default connection to a PostgreSQL database:

QmlSqlQueryModel

Object provides a read-only data model for SQL result sets