diff options
Diffstat (limited to 'src/corelib/doc/snippets/code')
3 files changed, 23 insertions, 6 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) |