diff options
Diffstat (limited to 'src/corelib/doc/snippets')
7 files changed, 64 insertions, 123 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_qpair.cpp b/src/corelib/doc/snippets/code/doc_src_qpair.cpp index f94e3b0d37..e62f91830c 100644 --- a/src/corelib/doc/snippets/code/doc_src_qpair.cpp +++ b/src/corelib/doc/snippets/code/doc_src_qpair.cpp @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <qmath.h> //! [0] QPair<QString, double> pair; @@ -55,7 +56,7 @@ QPair<QString, double> pair; //! [1] pair.first = "pi"; -pair.second = 3.14159265358979323846; +pair.second = M_PI; //! [1] //! [struct] @@ -65,10 +66,10 @@ struct Variable { }; Variable v; v.name = "pi"; -v.value = 3.14159265358979323846; +v.value = M_PI; //! [struct] //! [2] QList<QPair<int, double> > list; -list.append(qMakePair(66, 3.14159)); +list.append(qMakePair(66, M_PI)); //! [2] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp index 3794049f97..aed14c379f 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlocale.cpp @@ -103,3 +103,20 @@ d = german.toDouble( "1234.56", &ok ); // ok == false d = german.toDouble( "1.234", &ok ); // ok == true, d == 1234.0 //! [3] + +//! [3-qstringview] +bool ok; +double d; + +QLocale c(QLocale::C); +d = c.toDouble(u"1234.56", &ok); // ok == true, d == 1234.56 +d = c.toDouble(u"1,234.56", &ok); // ok == true, d == 1234.56 +d = c.toDouble(u"1234,56", &ok); // ok == false + +QLocale german(QLocale::German); +d = german.toDouble(u"1234,56", &ok); // ok == true, d == 1234.56 +d = german.toDouble(u"1.234,56", &ok); // ok == true, d == 1234.56 +d = german.toDouble(u"1234.56", &ok); // ok == false + +d = german.toDouble(u"1.234", &ok); // ok == true, d == 1234.0 +//! [3-qstringview] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp index 1fcb7b9945..7a2b4812ef 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp @@ -58,7 +58,7 @@ int main() { //! [0] QString string(QStringLiteral("a string")); -QStringIterator i(string); +QStringIterator i(string); // implicitly converted to QStringView //! [0] //! [1] @@ -71,8 +71,7 @@ while (i.hasNext()) { //! [2] -QString string(QStringLiteral("𝄞 is the G clef")); -QStringIterator i(string); +QStringIterator i(u"𝄞 is the G clef"); qDebug() << hex << i.next(); // will print 1d11e (U+1D11E, MUSICAL SYMBOL G CLEF) qDebug() << hex << i.next(); // will print 20 (U+0020, SPACE) qDebug() << hex << i.next(); // will print 69 (U+0069, LATIN SMALL LETTER I) diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp index 39b03f5ff3..e91c41b305 100644 --- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include <QtGui> +#include <QtWidgets> #include "buttonwidget.h" @@ -74,3 +75,18 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent) setLayout(gridLayout); } //! [2] + +//! [3] +ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent) + : QWidget(parent) +{ + QGridLayout *gridLayout = new QGridLayout; + for (int i = 0; i < texts.size(); ++i) { + QString text = texts[i]; + QPushButton *button = new QPushButton(text); + connect(button, &QPushButton::clicked, [=] { clicked(text); }); + gridLayout->addWidget(button, i / 3, i % 3); + } + setLayout(gridLayout); +} +//! [3] diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 41ee5a9cef..3d09e3618e 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -262,6 +262,17 @@ void Widget::argFunction() .arg(i).arg(total).arg(fileName); //! [11] + { + //! [11-qstringview] + int i; // current file's number + int total; // number of files to process + QStringView fileName; // current file's name + + QString status = QString("Processing file %1 of %2: %3") + .arg(i).arg(total).arg(fileName); + //! [11-qstringview] + } + //! [12] //! [13] QString str; //! [12] @@ -321,6 +332,12 @@ void Widget::compareSensitiveFunction() int y = QString::compare("auto", "Car", Qt::CaseSensitive); // y > 0 int z = QString::compare("auto", "Car", Qt::CaseInsensitive); // z < 0 //! [16] + + //! [QtPrivate::compareStrings-QSV-QSV] + int x = QtPrivate::compareStrings(u"aUtO", u"AuTo", Qt::CaseInsensitive); // x == 0 + int y = QtPrivate::compareStrings(u"auto", u"Car", Qt::CaseSensitive); // y > 0 + int z = QtPrivate::compareStrings(u"auto", u"Car", Qt::CaseInsensitive); // z < 0 + //! [QtPrivate::compareStrings-QSV-QSV] } void Widget::containsFunction() diff --git a/src/corelib/doc/snippets/qversionnumber/main.cpp b/src/corelib/doc/snippets/qversionnumber/main.cpp index 0e9997b6dc..27b7b1a7ef 100644 --- a/src/corelib/doc/snippets/qversionnumber/main.cpp +++ b/src/corelib/doc/snippets/qversionnumber/main.cpp @@ -95,6 +95,14 @@ void QObject::parse() // version is 5.4.0 // suffixIndex is 5 //! [3] + + //! [3-latin1-1] + QLatin1String string("5.4.0-alpha"); + int suffixIndex; + auto version = QVersionNumber::fromString(string, &suffixIndex); + // version is 5.4.0 + // suffixIndex is 5 + //! [3-latin1-1] } void Object::equivalent() diff --git a/src/corelib/doc/snippets/signalmapper/filereader.cpp b/src/corelib/doc/snippets/signalmapper/filereader.cpp deleted file mode 100644 index 674f73d671..0000000000 --- a/src/corelib/doc/snippets/signalmapper/filereader.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the config.tests of the Qt Toolkit. -** -** $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$ -** -****************************************************************************/ - -#include <QtGui> -#include "filereader.h" - - -FileReader::FileReader(QWidget *parent) - : QWidget(parent) -{ - textEdit = new QTextEdit; - - taxFileButton = new QPushButton("Tax File"); - accountFileButton = new QPushButton("Accounts File"); - reportFileButton = new QPushButton("Report File"); - -//! [0] - signalMapper = new QSignalMapper(this); - signalMapper->setMapping(taxFileButton, QString("taxfile.txt")); - signalMapper->setMapping(accountFileButton, QString("accountsfile.txt")); - signalMapper->setMapping(reportFileButton, QString("reportfile.txt")); - - connect(taxFileButton, &QPushButton::clicked, - signalMapper, &QSignalMapper::map); - connect(accountFileButton, &QPushButton::clicked, - signalMapper, &QSignalMapper::map); - connect(reportFileButton, &QPushButton::clicked, - signalMapper, &QSignalMapper::map); -//! [0] - -//! [1] - connect(signalMapper, SIGNAL(mapped(QString)), - this, SLOT(readFile(QString))); -//! [1] - -/* -//! [2] - //slower due to signature normalization at runtime - - connect(signalMapper, SIGNAL(mapped(QString)), - this, SLOT(readFile(QString))); -//! [2] -*/ - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addWidget(taxFileButton); - buttonLayout->addWidget(accountFileButton); - buttonLayout->addWidget(reportFileButton); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(textEdit); - mainLayout->addLayout(buttonLayout); - - setLayout(mainLayout); -} - -void FileReader::readFile(const QString &filename) -{ - QFile file(filename); - - if (!file.open(QIODevice::ReadOnly)) { - QMessageBox::information(this, tr("Unable to open file"), - file.errorString()); - return; - } - - - QTextStream in(&file); - textEdit->setPlainText(in.readAll()); -} - |