diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 4687d52e54..e03e705a0b 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -261,6 +261,19 @@ void Widget::argFunction() str.arg("%1f").arg("Hello"); // returns "Hellof %2" //! [13] + //! [97] + str = "%1%3%2"; + str.arg("Hello").arg(20).arg(50); // returns "Hello500" + + str = "%1%2%3"; + str.arg("Hello").arg(50).arg(20); // returns "Hello5020" + //! [97] + + //! [98] + str = "%1%2%3"; + str.arg("Hello", QString::number(20), QString::number(50)); // returns "Hello5020" + //! [98] + //! [14] str = QString("Decimal 63 is %1 in hexadecimal") .arg(63, 0, 16); diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index c933e261cc..bbb5647eea 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -7206,6 +7206,25 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const difference if \a a1 contains e.g. \c{%1}: \snippet qstring/main.cpp 13 + + A similar problem occurs when the numbered place markers are not + white space separated: + + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 97 + + Let's look at the substitutions: + \list + \li First, \c Hello replaces \c {%1} so the string becomes \c {"Hello%3%2"}. + \li Then, \c 20 replaces \c {%2} so the string becomes \c {"Hello%320"}. + \li Since the maximum numbered place marker value is 99, \c 50 replaces \c {%32}. + \endlist + Thus the string finally becomes \c {"Hello500"}. + + In such cases, the following yields the expected results: + + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 98 */ /*!