Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_sql_kernel_qsqldatabase_snippet.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [2]
5QSqlDatabase::registerSqlDriver("MYDRIVER", new QSqlDriverCreator<QSqlDriver>);
6QVERIFY(QSqlDatabase::drivers().contains("MYDRIVER"));
7QSqlDatabase db = QSqlDatabase::addDatabase("MYDRIVER");
8QVERIFY(db.isValid());
9//! [2]
10//! [6]
11PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
12QPSQLDriver *drv = new QPSQLDriver(con);
13QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
15query.exec("SELECT NAME, ID FROM STAFF");
16//! [6]
17
18//! [7]
19unix:LIBS += -lpq
20win32:LIBS += libpqdll.lib
21//! [7]
QSqlQuery query
[36]
PGconn * con
[2] [6]
QVERIFY(db.isValid())