1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QSqlDatabase>
4#include <QSqlQuery>
5#include <QSqlDriver>
6#include <QVariant>
7
8void checkHandle()
9{
10//dummy definitions
11typedef void sqlite3;
12typedef void PGconn;
13typedef void MYSQL;
14//! [0]
15QSqlDatabase db = QSqlDatabase::database();
16QVariant v = db.driver()->handle();
17if (v.isValid() && (qstrcmp(str1: v.typeName(), str2: "sqlite3*") == 0)) {
18 // v.data() returns a pointer to the handle
19 sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
20 if (handle) {
21 // ...
22 }
23}
24//! [0]
25
26//! [1]
27if (qstrcmp(str1: v.typeName(), str2: "PGconn*") == 0) {
28 PGconn *handle = *static_cast<PGconn **>(v.data());
29 if (handle) {
30 // ...
31 }
32}
33
34if (qstrcmp(str1: v.typeName(), str2: "MYSQL*") == 0) {
35 MYSQL *handle = *static_cast<MYSQL **>(v.data());
36 if (handle) {
37 // ...
38 }
39}
40//! [1]
41}
42

source code of qtbase/src/sql/doc/snippets/code/src_sql_kernel_qsqldriver.cpp