QT Development (47)--Database driver layer

Source: Internet
Author: User
Tags export class

QT Development (47)--database driver layer

the drive layer is for specific databases andSQLThe interface layer provides the underlying bridge, the main classincludeQt SQLModulein theQsqldriver,Qsqldrivercreator,Qsqldrivercreatorbase,Qsqldriverpluginand theQsqlresult.

First, Qsqldriver

Qsqldriver is to visit the specific SQL the abstract base class of the database, which cannot be used directly. If you want to create a custom database driver, you can override The pure virtual and virtual functions of the Qsqldriver class as needed.

Custom Database Drivers

Qsqldatabase responsible for loading and managing the database driver plug-in. When a database is added, the corresponding database driver plug-in is loaded. the qsqldatabase relies on driver plug-ins to provide interfaces for Qsqldriver and qsqlresult .

Qsqldriver is to define the abstract base class for SQL database functionality.

Second, Qsqldrivercreator

    qsqldrivercreator is to provide <t> types of instantiated objects

[virtual] Qsqldriver *qsqldrivercreator::createobject () const

the Qsqldrivercreatorbase::createobject () override of function

Third, Qsqldrivercreatorbase

Qsqldrivercreatorbase is a base class for SQL-driven factories.

[pure virtual] Qsqldriver *qsqldrivercreatorbase::createobject () const

Override this function to return a Qsqldriver instances of subclasses

Four, Qsqldriverplugin

Qsqldriverplugin class provides a custom Qsqldriver the abstract base class for the plug-in.

The SQL database driver plugin is a simple plug-in interface that can be easily created by a custom SQL database driver plug-in that is dynamically loaded by QT.

Write The SQL plug-in can be implemented by deriving the qsqldriverplugin class, overriding the pure virtual function Create (), using the macro q_plugin_metadata () export class.

Pure virtual] Qsqldriver *qsqldriverplugin::create (const QString &key)

creates and returns a Qsqldriver object with a drive named key

Five, Qsqlresult

Qsqlresult class provides access to the specific abstract interface for SQL database data.

     Usually use qsqlresult qsqlquery provides a database-specific qsqlresult universal packaging implemented.

If you derive from Qsqldriver Implementing a custom SQL driver, you need to provide a custom implementation of all pure virtual functions and required virtual functions Qsqlresult sub-class.

[protected] qsqlresult::qsqlresult (const qsqldriver *db)

using Database Drivers db to build a Qsqlresult Object


This article from "Life is endless, struggle not only" blog, declined reprint!

QT Development (47)--Database driver layer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.