An error occurred while loading the file. Please try again.
-
Ronald S. Bultje authored
Change-Id: I0027483e47900de84394de47c3273cc8292e6119
65d22825
datastorage.qdoc 9.86 KiB
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page topics-data-storage.html
\title Data Storage
\brief Qt's data storage features
\section1 Saving and Loading Data
The QIODevice class is the base class for all file and data storage devices
in \l {Qt Core}. All classes that are used for reading and writing data
inherit from it.
Examples of devices are QFile, QBuffer, QTcpSocket, and QProcess.
QFile is used for reading and writing text, binary files, and resources.
The QBuffer class provides a QIODevice interface for a QByteArray.
QTcpSocket enables the developer to establish a TCP connection and transfer
streams of data. QProcess is used to start external programs, and to read
from and write to that process.
\list
\li \l {Input/Output and Networking} (list of I/O related classes)
\li \l {File and Datastream Functions}
\li \l {Serializing Qt Data Types}
\endlist
\section1 SQL support in Qt
The \l {Qt SQL} module uses driver plugins to communicate with several database
APIs. Qt has drivers for SQLite, MYSQL, DB2, Borland InterBase, Oracle, ODBC,
and PostgreSQL. It is also possible to develop your own driver if Qt does not
provide the driver needed.
Qt's SQL classes can be divided in 3 layers:
\table
\header
\li Layer
\li Purpose
\li Example class
\row
\li
\list
\li Driver layer
\li SQL API layer
\li User Interface layer
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
\endlist
\li
\list
\li Low-level communication between database and the SQL API layer
\li Provide access to databases
\li Link data from a database to data-aware widgets
\endlist
\li
\list
\li QSqlDriver, QSqlDriverCreator
\li QSqlDatabase, QSqlQuery
\li QSqlQueryModel (readonly), QSqlTableModel (read/write), QSqlRelationalTableModel (read/write with foreign-key support)
\endlist
\endtable
QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel can be used as a
datasource for Qt's classes for viewing data. QSqlTableModel, and
QtSqlRelationalTableModel provide editable models for use with Qt's item views.
QSqlTableModel has read/write access to a single table. QSqlRelationalTableModel
has read/write access to the main table, not to the table where the foreign key
comes from.
With the MYSQL driver, it is possible to connect to a MYSQL server. In order to
build the QMYSQL Plugin for Unix or Mac OS X, you need the MYSQL header files
as well as the shared library libmysqlclient.so. To compile the plugin
for Windows, you need to get the MYSQL installation files and run SETUP.EXE.
If you use the embedded MYSQL Server, you do not need a MYSQL server in order
to use that database system. In order to do so, you need to link the Qt plugin
to libmysqld instead of libmysqlclient.
The Qt SQLite plugin is very suitable for local storage. SQLite is a relational
database management system contained in a small (~350 KiB) C library.
In contrast to other database management systems, SQLite is not a separate process
that is accessed from the client application, but an integral part of it. SQLite
operates on a single file, which must be set as the database name when opening
a connection. If the file does not exist, SQLite will try to create it.
SQLite has some restrictions regarding multiple users and multiple transactions.
If you are reading or writing on a file from different transactions, your
application might freeze until one transaction commits or rolls back.
\list
\li \l {Qt SQL}
\li \l {Qt SQL Module - C++ Classes}
\li \l {Connecting to Databases}
\li \l {SQL Database Drivers}
\li \l {Creating Data-Aware Forms}
\li \l {Using the SQL Model Classes}
\li \l {Presenting Data in a Table View}
\li \l {SQL Programming}
\li \l {Executing SQL Statements}
\li \l {Data Types for Qt-supported Database Systems}
\li \l {Qt Quick Local Storage QML Types}
\endlist
\section1 XML Support in Qt
The QXmlStreamReader class provides a fast parser for reading XML via a simple
streaming API. QXmlStreamReader is a well-formed XML 1.0 parser that does not
include external parsed entities. As long as no error occurs, the application
code can assume that the XML follows \l {W3C XML specifications}.
QXmlStreamReader understands and resolves XML namespaces. For example, in
case of a StartElement, namespaceUri() returns the namespace the element
is in, and name() returns the element's local name. The combination of
namespaceUri() and name() uniquely identifies an element.
QXmlStreamReader does not put a high load on the CPU, since it doesn't store
the entire XML document tree in memory, but only the current token at the time