aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/doc/codesnippets/doc/src/snippets/code
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-07-03 08:24:42 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-07-03 13:42:12 +0200
commit3dd32863337ea2f6308ebf2f7656795d3fd488c9 (patch)
tree08a3b35607dee19536ccb5f21b2ede0fdc41cc79 /sources/pyside2/doc/codesnippets/doc/src/snippets/code
parent4f4f1be9f46e02e87357aeee613cfd5ea0be8220 (diff)
parent67d635fe2cc2c89c30486a2e26dea4106a9d9c16 (diff)
Merge "Merge remote-tracking branch 'origin/5.13' into dev"
Diffstat (limited to 'sources/pyside2/doc/codesnippets/doc/src/snippets/code')
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp514
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp152
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp60
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp146
4 files changed, 0 insertions, 872 deletions
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp
deleted file mode 100644
index c172beb21..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_global_qglobal.cpp
+++ /dev/null
@@ -1,514 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
-//! [0]
-
-
-//! [1]
-class MyClass
-{
-public:
- enum Option {
- NoOptions = 0x0,
- ShowTabs = 0x1,
- ShowAll = 0x2,
- SqueezeBlank = 0x4
- };
- Q_DECLARE_FLAGS(Options, Option)
- ...
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)
-//! [1]
-
-//! [meta-object flags]
-Q_FLAGS(Options)
-//! [meta-object flags]
-
-//! [2]
-typedef QFlags<Enum> Flags;
-//! [2]
-
-
-//! [3]
-int myValue = 10;
-int minValue = 2;
-int maxValue = 6;
-
-int boundedValue = qBound(minValue, myValue, maxValue);
-// boundedValue == 6
-//! [3]
-
-
-//! [4]
-if (!driver()->isOpen() || driver()->isOpenError()) {
- qWarning("QSqlQuery::exec: database not open");
- return false;
-}
-//! [4]
-
-
-//! [5]
-qint64 value = Q_INT64_C(932838457459459);
-//! [5]
-
-
-//! [6]
-quint64 value = Q_UINT64_C(932838457459459);
-//! [6]
-
-
-//! [7]
-void myMsgHandler(QtMsgType, const char *);
-//! [7]
-
-
-//! [8]
-qint64 value = Q_INT64_C(932838457459459);
-//! [8]
-
-
-//! [9]
-quint64 value = Q_UINT64_C(932838457459459);
-//! [9]
-
-
-//! [10]
-myValue = -4
-absoluteValue = qAbs(myValue)
-// absoluteValue == 4
-//! [10]
-
-
-//! [11]
-valueA = 2.3
-valueB = 2.7
-
-roundedValueA = qRound(valueA)
-// roundedValueA = 2
-roundedValueB = qRound(valueB)
-// roundedValueB = 3
-//! [11]
-
-
-//! [12]
-valueA = 42949672960.3
-valueB = 42949672960.7
-
-roundedValueA = qRound(valueA)
-// roundedValueA = 42949672960
-roundedValueB = qRound(valueB)
-// roundedValueB = 42949672961
-//! [12]
-
-
-//! [13]
-myValue = 6
-yourValue = 4
-
-minValue = qMin(myValue, yourValue)
-// minValue == yourValue
-//! [13]
-
-
-//! [14]
-myValue = 6
-yourValue = 4
-
-maxValue = qMax(myValue, yourValue)
-// maxValue == myValue
-//! [14]
-
-
-//! [15]
-myValue = 10
-minValue = 2
-maxValue = 6
-
-boundedValue = qBound(minValue, myValue, maxValue)
-// boundedValue == 6
-//! [15]
-
-
-//! [16]
-#if QT_VERSION >= 0x040100
- QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
-#else
- QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
- QIcon icon(pixmap);
-#endif
-//! [16]
-
-
-//! [17]
-// File: div.cpp
-
-#include <QtGlobal>
-
-int divide(int a, int b)
-{
- Q_ASSERT(b != 0);
- return a / b;
-}
-//! [17]
-
-
-//! [18]
-ASSERT: "b == 0" in file div.cpp, line 7
-//! [18]
-
-
-//! [19]
-// File: div.cpp
-
-#include <QtGlobal>
-
-int divide(int a, int b)
-{
- Q_ASSERT_X(b != 0, "divide", "division by zero");
- return a / b;
-}
-//! [19]
-
-
-//! [20]
-ASSERT failure in divide: "division by zero", file div.cpp, line 7
-//! [20]
-
-
-//! [21]
-int *a;
-
-Q_CHECK_PTR(a = new int[80]); // WRONG!
-
-a = new (nothrow) int[80]; // Right
-Q_CHECK_PTR(a);
-//! [21]
-
-
-//! [22]
-template<typename TInputType>
-const TInputType &myMin(const TInputType &value1, const TInputType &value2)
-{
- qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2;
-
- if(value1 < value2)
- return value1;
- else
- return value2;
-}
-//! [22]
-
-
-//! [23]
-#include <qapplication.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-void myMessageOutput(QtMsgType type, const char *msg)
-{
- switch (type) {
- case QtDebugMsg:
- fprintf(stderr, "Debug: %s\n", msg);
- break;
- case QtWarningMsg:
- fprintf(stderr, "Warning: %s\n", msg);
- break;
- case QtCriticalMsg:
- fprintf(stderr, "Critical: %s\n", msg);
- break;
- case QtFatalMsg:
- fprintf(stderr, "Fatal: %s\n", msg);
- abort();
- }
-}
-
-int main(int argc, char **argv)
-{
- qInstallMsgHandler(myMessageOutput);
- QApplication app(argc, argv);
- ...
- return app.exec();
-}
-//! [23]
-
-
-//! [24]
-qDebug("Items in list: %d", myList.size());
-//! [24]
-
-
-//! [25]
-qDebug() << "Brush:" << myQBrush << "Other value:" << i;
-//! [25]
-
-
-//! [26]
-void f(int c)
-{
- if (c > 200)
- qWarning("f: bad argument, c == %d", c);
-}
-//! [26]
-
-
-//! [27]
-qWarning() << "Brush:" << myQBrush << "Other value:"
-<< i;
-//! [27]
-
-
-//! [28]
-void load(const QString &fileName)
-{
- QFile file(fileName);
- if (!file.exists())
- qCritical("File '%s' does not exist!", qPrintable(fileName));
-}
-//! [28]
-
-
-//! [29]
-qCritical() << "Brush:" << myQBrush << "Other
-value:" << i;
-//! [29]
-
-
-//! [30]
-int divide(int a, int b)
-{
- if (b == 0) // program error
- qFatal("divide: cannot divide by zero");
- return a / b;
-}
-//! [30]
-
-
-//! [31]
-forever {
- ...
-}
-//! [31]
-
-
-//! [32]
-CONFIG += no_keywords
-//! [32]
-
-
-//! [33]
-CONFIG += no_keywords
-//! [33]
-
-
-//! [34]
-QString FriendlyConversation::greeting(int type)
-{
-static const char *greeting_strings[] = {
- QT_TR_NOOP("Hello"),
- QT_TR_NOOP("Goodbye")
-};
-return tr(greeting_strings[type]);
-}
-//! [34]
-
-
-//! [35]
-static const char *greeting_strings[] = {
- QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
- QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
-};
-
-QString FriendlyConversation::greeting(int type)
-{
- return tr(greeting_strings[type]);
-}
-
-QString global_greeting(int type)
-{
- return qApp->translate("FriendlyConversation",
- greeting_strings[type]);
-}
-//! [35]
-
-
-//! [36]
-
-static { const char *source; const char *comment; } greeting_strings[] =
-{
- QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
- "A really friendly hello"),
- QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
- "A really friendly goodbye")
-};
-
-QString FriendlyConversation::greeting(int type)
-{
- return tr(greeting_strings[type].source,
- greeting_strings[type].comment);
-}
-
-QString global_greeting(int type)
-{
- return qApp->translate("FriendlyConversation",
- greeting_strings[type].source,
- greeting_strings[type].comment);
-}
-//! [36]
-
-
-//! [37]
-qWarning("%s: %s", qPrintable(key), qPrintable(value));
-//! [37]
-
-
-//! [38]
-struct Point2D
-{
- int x;
- int y;
-};
-
-Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);
-//! [38]
-
-
-//! [39]
-class Point2D
-{
-public:
- Point2D() { data = new int[2]; }
- Point2D(const Point2D &other) { ... }
- ~Point2D() { delete[] data; }
-
- Point2D &operator=(const Point2D &other) { ... }
-
- int x() const { return data[0]; }
- int y() const { return data[1]; }
-
-private:
- int *data;
-};
-
-Q_DECLARE_TYPEINFO(Point2D, Q_MOVABLE_TYPE);
-//! [39]
-
-
-//! [40]
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-...
-#endif
-
-or
-
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
-...
-#endif
-
-//! [40]
-
-
-//! [41]
-
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
-...
-#endif
-
-//! [41]
-
-
-//! [42]
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-...
-#endif
-
-//! [42]
-
-//! [begin namespace macro]
-namespace QT_NAMESPACE {
-//! [begin namespace macro]
-
-//! [end namespace macro]
-}
-//! [end namespace macro]
-
-//! [43]
-class MyClass : public QObject
-{
-
- private:
- Q_DISABLE_COPY(MyClass)
-};
-
-//! [43]
-
-//! [44]
-class MyClass : public QObject
-{
-
- private:
- MyClass(const MyClass &);
- MyClass &operator=(const MyClass &);
-};
-//! [44]
-
-//! [45]
- w = QWidget()
-//! [45]
-
-//! [46]
- // Instead of comparing with 0.0
- qFuzzyCompare(0.0,1.0e-200); // This will return false
- // Compare adding 1 to both values will fix the problem
- qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
-//! [46]
-
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp
deleted file mode 100644
index 55cdf8148..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-ret = QMessageBox.warning(self, self.tr("My Application"),
- self.tr("The document has been modified.\n" + \
- "Do you want to save your changes?"),
- QMessageBox.Save | QMessageBox.Discard
- | QMessageBox.Cancel,
- QMessageBox.Save)
-//! [0]
-
-
-//! [1]
-msgBox = QMessageBox()
-msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
-result = msgBox.exec_()
-
-if result == QMessageBox.Yes:
- # yes was clicked
-elif result == QMessageBox.No:
- # no was clicked
-else:
- # should never be reached
-//! [1]
-
-
-//! [2]
-msgBox = QMessageBox()
-connectButton = msgBox.addButton(self.tr("Connect"), QMessageBox.ActionRole)
-abortButton = msgBox.addButton(QMessageBox.Abort)
-
-msgBox.exec_()
-
-if msgBox.clickedButton() == connectButton:
- # connect
-elif msgBox.clickedButton() == abortButton:
- # abort
-}
-//! [2]
-
-
-//! [3]
-messageBox = QMessageBox(self)
-disconnectButton = messageBox.addButton(self.tr("Disconnect"),
- QMessageBox.ActionRole)
-...
-messageBox.exec_()
-if messageBox.clickedButton() == disconnectButton:
- ...
-
-//! [3]
-
-
-//! [4]
-#include <QApplication>
-#include <QMessageBox>
-
-int main(int argc, char *argv[])
-{
-# Not Supported by PySide
- QT_REQUIRE_VERSION(argc, argv, "4.0.2")
-
- QApplication app(argc, argv);
- ...
- return app.exec();
-}
-//! [4]
-
-//! [5]
-msgBox = QMessageBox()
-msgBox.setText("The document has been modified.")
-msgBox.exec_()
-//! [5]
-
-//! [6]
-msgBox = QMessageBox()
-msgBox.setText("The document has been modified.")
-msgBox.setInformativeText("Do you want to save your changes?")
-msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
-msgBox.setDefaultButton(QMessageBox.Save)
-ret = msgBox.exec_()
-//! [6]
-
-//! [7]
-
-if ret == QMessageBox.Save:
- # Save was clicked
-elif ret == QMessageBox.Discard:
- # Don't save was clicked
-elif ret == QMessageBox.Cancel:
- # cancel was clicked
-else:
- # should never be reached
-
-//! [7]
-
-//! [9]
-msgBox = QMessageBox(self)
-msgBox.setText(tr("The document has been modified.\n" + \
- "Do you want to save your changes?"))
-msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
- | QMessageBox.Cancel)
-msgBox.setDefaultButton(QMessageBox.Save)
-//! [9]
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp
deleted file mode 100644
index 201d14fbe..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_gui_text_qtextdocument.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-plain = QString("#include <QtCore>")
-html = Qt::escape(plain)
-# html == "#include &lt;QtCore&gt;"
-//! [0]
-
-
-//! [1]
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>...
-//! [1]
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp
deleted file mode 100644
index 6bf0e003b..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqldatabase.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-# WRONG
-db = QSqlDatabase.database("sales")
-query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db)
-QSqlDatabase.removeDatabase("sales") # will output a warning
-
-# "db" is now a dangling invalid database connection,
-# "query" contains an invalid result set
-//! [0]
-
-
-//! [1]
-db = QSqlDatabase.database("sales")
-query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db)
-# Both "db" and "query" are destroyed because they are out of scope
-QSqlDatabase.removeDatabase("sales") # correct
-//! [1]
-
-
-//! [2]
-class MyDatabaseDriverCreatorBase(QtSql.QSqlDriverCreatorBase):
- ...
- def createObject(self):
- return MyDatabaseDriver()
-
-mydriver = MyDatabaseDriverCreatorBase()
-QtSql.QSqlDatabase.registerSqlDriver("MYDRIVER", mydriver)
-db = QtSql.QSqlDatabase.addDatabase("MYDRIVER")
-//! [2]
-
-
-//! [3]
-...
-db = QSqlDatabase.addDatabase("QODBC")
-db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb")
-if db.open():
- # success!
- pass
-...
-//! [3]
-
-
-//! [4]
-...
-# MySQL connection
-db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1") # use an SSL connection to the server
-if not db.open():
- db.setConnectOptions() # clears the connect option string
- ...
-...
-# PostgreSQL connection
-db.setConnectOptions("requiressl=1") # enable PostgreSQL SSL connections
-if not db.open():
- db.setConnectOptions() # clear options
- ...
-...
-# ODBC connection
-# set ODBC options
-db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON")
-if not db.open():
- db.setConnectOptions() # don't try to set this option
- ...
-//! [4]
-
-
-//! [5]
-#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"
-//! [5]
-
-
-//! [6]
-con = PQconnectdb("host=server user=bart password=simpson dbname=springfield")
-drv = QPSQLDriver(con)
-db = QSqlDatabase.addDatabase(drv) # becomes the new default connection
-query = QSqlQuery()
-query.exec_("SELECT NAME, ID FROM STAFF")
-...
-//! [6]
-
-
-//! [7]
-unix:LIBS += -lpq
-win32:LIBS += libpqdll.lib
-//! [7]
-
-
-//! [8]
-db = QSqlDatabase()
-print(db.isValid()) # Returns False
-
-db = QSqlDatabase.database("sales")
-print(db.isValid()) # Returns True if "sales" connection exists
-
-QSqlDatabase.removeDatabase("sales")
-print(db.isValid()) # Returns False
-//! [8]