From 6a7a4aac0a94650247d8578475a8725009d7d569 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 17 Nov 2019 00:11:21 +0100 Subject: [PATCH 1/6] Doc: add warning for binding values in QSqlQuery Not all SQL operations support binding values like the PRAGMA instruction of SQLite. This patch adds a warning for the developer to make it clearer that binding values cannot be used for everything. Task-number: QTBUG-80082 Change-Id: Ie1d33815d74a0759a3593df9410b8bad448f6fe9 Reviewed-by: Sze Howe Koh --- src/sql/kernel/qsqlquery.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index e7c444f5b93..34a3ba37555 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -182,6 +182,9 @@ QSqlQueryPrivate::~QSqlQueryPrivate() You can retrieve the values of all the fields in a single variable (a map) using boundValues(). + \note Not all SQL operations support binding values. Refer to your database + system's documentation to check their availability. + \section1 Approaches to Binding Values Below we present the same example using each of the four From 9567103f388af8f07042744706f0d5b9f0d18e22 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 17 Nov 2019 20:09:00 +0800 Subject: [PATCH 2/6] qmake: Remove /O3 from win32-icc Use O3 causes warnings when combined with O2, so just remove it. Partially revert commit 11111c5a7d71024f281322d9b310ce37210fc4c2 Change-Id: Ifbf6e024e35933ecc3610d6efc3423589dab9a38 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- qmake/Makefile.win32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 7324817af27..4e7724f14ec 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -13,7 +13,7 @@ QMKSRC = $(SOURCE_PATH)\qmake !if "$(QMAKESPEC)" == "win32-icc" CXX = icl LINKER = xilink -CFLAGS_EXTRA = /Zc:forScope /Qstd=c++11 /O3 +CFLAGS_EXTRA = /Zc:forScope /Qstd=c++11 !elseif "$(QMAKESPEC)" == "win32-clang-msvc" CXX = clang-cl LINKER = lld-link From 54d5ca0c2766e915c960fa437cee6c20a324c1a7 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 16 Nov 2019 16:53:08 +0100 Subject: [PATCH 3/6] Doc: improve Using Model Indexes in Model View Programming guide The current example using QFileSystemModel doesn't take into account the asynchronous nature of that model. This puts people on the wrong path on how to use it. This patch improves the snippet as well as the explanation steps. Change-Id: I5c7a3c19aad48847f0b965b5eb69b492d6263f51 Reviewed-by: Paul Wicking --- src/widgets/doc/snippets/simplemodel-use/main.cpp | 7 +++++-- src/widgets/doc/src/model-view-programming.qdoc | 13 +++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/widgets/doc/snippets/simplemodel-use/main.cpp b/src/widgets/doc/snippets/simplemodel-use/main.cpp index 3e106c8eeaf..940669e1011 100644 --- a/src/widgets/doc/snippets/simplemodel-use/main.cpp +++ b/src/widgets/doc/snippets/simplemodel-use/main.cpp @@ -79,8 +79,11 @@ int main(int argc, char *argv[]) //! [0] QFileSystemModel *model = new QFileSystemModel; - QModelIndex parentIndex = model->index(QDir::currentPath()); - int numRows = model->rowCount(parentIndex); + connect(model, &QFileSystemModel::directoryLoaded, [model](const QString &directory) { + QModelIndex parentIndex = model->index(directory); + int numRows = model->rowCount(parentIndex); + }); + model->setRootPath(QDir::currentPath); //! [0] //! [1] diff --git a/src/widgets/doc/src/model-view-programming.qdoc b/src/widgets/doc/src/model-view-programming.qdoc index 236582ef3fc..ede1ebf9327 100644 --- a/src/widgets/doc/src/model-view-programming.qdoc +++ b/src/widgets/doc/src/model-view-programming.qdoc @@ -465,14 +465,19 @@ Although this does not show a normal way of using a model, it demonstrates the conventions used by models when dealing with model indexes. + QFileSystemModel loading is asynchronous to minimize system resource use. + We have to take that into account when dealing with this model. + We construct a file system model in the following way: \snippet simplemodel-use/main.cpp 0 - In this case, we set up a default QFileSystemModel, obtain a parent index - using a specific implementation of \l{QFileSystemModel::}{index()} - provided by that model, and we count the number of rows in the model using - the \l{QFileSystemModel::}{rowCount()} function. + In this case, we start by setting up a default QFileSystemModel. We connect + it to a lambda, in which we will obtain a parent index using a specific + implementation of \l{QFileSystemModel::}{index()} provided by that model. + In the lambda, we count the number of rows in the model using the + \l{QFileSystemModel::}{rowCount()} function. Finally, we set the root path + of the QFileSystemModel so it starts loading data and triggers the lambda. For simplicity, we are only interested in the items in the first column of the model. We examine each row in turn, obtaining a model index for From ede867f581c0894e13d669f5364610df7ade0eb5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 17 Nov 2019 13:10:41 +0100 Subject: [PATCH 4/6] QWheelEvent: add \since flag for ctor c08bf215cceda784cd02f8fa20e5b2431e0d9ef9 added a new QWheelEvent ctor but missed the \since flag. Fixes: QTBUG-80088 Change-Id: I6c81179999dd100162dc0cd5dc28e7b5b843b437 Reviewed-by: Shawn Rutledge --- src/gui/kernel/qevent.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 2b28052dd52..f555f4dc05e 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -846,6 +846,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, /*! Constructs a wheel event object. + \since 5.12 The \a pos provides the location of the mouse cursor within the window. The position in global coordinates is specified by \a globalPos. From d7cb21ac085117f879a8aa1d7727b2ca52d3353d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 15 Nov 2019 21:46:32 +0100 Subject: [PATCH 5/6] QDom: use QLocale::C when converting a double to a xml attribute QDomElement::setAttribute(QString, double) did not use QString::setNum() but qsnprintf(). This is wrong because qsnprintf() is using the current locale instead QLocale::C. It was also inconsistent to QDomElement::setAttributeNS() which was already using QString::setNum(). Also fix the documentation which stated that all QDomElement::setAttribute() format the values according the current locale. Fixes: QTBUG-80068 Change-Id: Iabb0b39c0d0723060527542c283a5435f26f31ca Reviewed-by: Thiago Macieira --- src/xml/dom/qdom.cpp | 19 +++----- tests/auto/xml/dom/qdom/tst_qdom.cpp | 69 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 8d232237bfa..04151c3f31d 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -4818,20 +4818,20 @@ void QDomElement::setAttribute(const QString& name, const QString& value) \fn void QDomElement::setAttribute(const QString& name, int value) \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ /*! \fn void QDomElement::setAttribute(const QString& name, uint value) \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ /*! \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ void QDomElement::setAttribute(const QString& name, qlonglong value) { @@ -4845,7 +4845,7 @@ void QDomElement::setAttribute(const QString& name, qlonglong value) /*! \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ void QDomElement::setAttribute(const QString& name, qulonglong value) { @@ -4859,7 +4859,7 @@ void QDomElement::setAttribute(const QString& name, qulonglong value) /*! \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ void QDomElement::setAttribute(const QString& name, float value) { @@ -4873,19 +4873,14 @@ void QDomElement::setAttribute(const QString& name, float value) /*! \overload - The number is formatted according to the current locale. + The formatting always uses QLocale::C. */ void QDomElement::setAttribute(const QString& name, double value) { if (!impl) return; QString x; - char buf[256]; - int count = qsnprintf(buf, sizeof(buf), "%.16g", value); - if (count > 0) - x = QString::fromLatin1(buf, count); - else - x.setNum(value); // Fallback + x.setNum(value); IMPL->setAttribute(name, x); } diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index b09a3447e33..99639df5b01 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -57,6 +57,7 @@ private slots: void toString_02(); void hasAttributes_data(); void hasAttributes(); + void setGetAttributes(); void save_data(); void save(); void saveWithSerialization() const; @@ -392,6 +393,74 @@ void tst_QDom::hasAttributes() QTEST( visitedNodes, "visitedNodes" ); } +void tst_QDom::setGetAttributes() +{ + QDomDocument doc; + QDomElement rootNode = doc.createElement("Root"); + doc.appendChild(rootNode); + + const QLocale oldLocale = QLocale(); + QLocale::setDefault(QLocale::German); // decimal separator != '.' + + const QString qstringVal("QString"); + const qlonglong qlonglongVal = std::numeric_limits::min(); + const qulonglong qulonglongVal = std::numeric_limits::max(); + const int intVal = std::numeric_limits::min(); + const uint uintVal = std::numeric_limits::max(); + const float floatVal = 0.1234f; + const double doubleVal = 0.1234; + + rootNode.setAttribute("qstringVal", qstringVal); + rootNode.setAttribute("qlonglongVal", qlonglongVal); + rootNode.setAttribute("qulonglongVal", qulonglongVal); + rootNode.setAttribute("intVal", intVal); + rootNode.setAttribute("uintVal", uintVal); + rootNode.setAttribute("floatVal", floatVal); + rootNode.setAttribute("doubleVal", doubleVal); + + QDomElement nsNode = doc.createElement("NS"); + rootNode.appendChild(nsNode); + nsNode.setAttributeNS("namespace", "qstringVal", qstringVal); + nsNode.setAttributeNS("namespace", "qlonglongVal", qlonglongVal); + nsNode.setAttributeNS("namespace", "qulonglongVal", qulonglongVal); + nsNode.setAttributeNS("namespace", "intVal", intVal); + nsNode.setAttributeNS("namespace", "uintVal", uintVal); + nsNode.setAttributeNS("namespace", "floatVal", floatVal); // not available atm + nsNode.setAttributeNS("namespace", "doubleVal", doubleVal); + + bool bOk; + QCOMPARE(rootNode.attribute("qstringVal"), qstringVal); + QCOMPARE(rootNode.attribute("qlonglongVal").toLongLong(&bOk), qlonglongVal); + QVERIFY(bOk); + QCOMPARE(rootNode.attribute("qulonglongVal").toULongLong(&bOk), qulonglongVal); + QVERIFY(bOk); + QCOMPARE(rootNode.attribute("intVal").toInt(&bOk), intVal); + QVERIFY(bOk); + QCOMPARE(rootNode.attribute("uintVal").toUInt(&bOk), uintVal); + QVERIFY(bOk); + QCOMPARE(rootNode.attribute("floatVal").toFloat(&bOk), floatVal); + QVERIFY(bOk); + QCOMPARE(rootNode.attribute("doubleVal").toDouble(&bOk), doubleVal); + QVERIFY(bOk); + + QCOMPARE(nsNode.attributeNS("namespace", "qstringVal"), qstringVal); + QCOMPARE(nsNode.attributeNS("namespace", "qlonglongVal").toLongLong(&bOk), qlonglongVal); + QVERIFY(bOk); + QCOMPARE(nsNode.attributeNS("namespace", "qulonglongVal").toULongLong(&bOk), qulonglongVal); + QVERIFY(bOk); + QCOMPARE(nsNode.attributeNS("namespace", "intVal").toInt(&bOk), intVal); + QVERIFY(bOk); + QCOMPARE(nsNode.attributeNS("namespace", "uintVal").toUInt(&bOk), uintVal); + QVERIFY(bOk); + QCOMPARE(nsNode.attributeNS("namespace", "floatVal").toFloat(&bOk), floatVal); + QVERIFY(bOk); + QCOMPARE(nsNode.attributeNS("namespace", "doubleVal").toDouble(&bOk), doubleVal); + QVERIFY(bOk); + + QLocale::setDefault(oldLocale); +} + + int tst_QDom::hasAttributesHelper( const QDomNode& node ) { int visitedNodes = 1; From 315c2c468e504b83d616e2068bd4f7688ff58cf7 Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Fri, 15 Nov 2019 09:37:05 +0200 Subject: [PATCH 6/6] tst_QScopeGuard: Remove unused lambda capture qt5/qtbase/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp:100:38: warning: lambda capture 'caught' is not used [-Wunused-lambda-capture] auto cleanup = qScopeGuard([&caught] { s_globalState++; }); ~^~~~~~ Change-Id: I0d9b85896594f3ea35c8003846d4ac7ab5e33d16 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp index f95d48f042f..01181ce20ed 100644 --- a/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp +++ b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp @@ -67,7 +67,7 @@ void tst_QScopedGuard::exceptions() bool caught = false; QT_TRY { - auto cleanup = qScopeGuard([&caught] { s_globalState++; }); + auto cleanup = qScopeGuard([] { s_globalState++; }); QT_THROW(std::bad_alloc()); //if Qt compiled without exceptions this is noop s_globalState = 100; }