From ab1ce95c8ce38683477373cf84ba5686ea00efed Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Mar 2025 15:57:00 +0100 Subject: [PATCH] [docs] QString: fix link and formatting in the qPrintable() discussion The old code used a `` to indicate an object of QString type. I have not seen this pattern used elsewhere, so rewrite the expression to say "call X on the QString" instead of "call .X". Also, the constData() link in the expression ('X' in the previous paragraph) was unqualified, so resolved to QString::constData(), but the result of toLocal8Bit() is a QByteArray, and it's thence the link should point to. Redirect it manually whereever we fell into that trap. Amends the start of the public history. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: I2204522351976be0f045bfd60a30c82c9e784dd6 Reviewed-by: Edward Welbourne Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira --- src/corelib/text/qstring.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 582082a0442..40987ee3ec3 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1803,7 +1803,8 @@ void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *whe constructor. Similarly, you can pass a QString to a function that takes a \c{const char *} argument using the \l qPrintable() macro, which returns the given QString as a \c{const char *}. This is - equivalent to calling .toLocal8Bit().constData(). + equivalent to calling toLocal8Bit().\l{QByteArray::}{constData()} + on the QString. \section1 Manipulating string data @@ -2007,7 +2008,7 @@ void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *whe \snippet qstring/main.cpp 8 All functions except isNull() treat null strings the same as empty - strings. For example, toUtf8().constData() returns a valid pointer + strings. For example, toUtf8().\l{QByteArray::}{constData()} returns a valid pointer (not \nullptr) to a '\\0' character for a null string. We recommend that you always use the isEmpty() function and avoid isNull(). @@ -10272,7 +10273,7 @@ void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out) noe \relates QString Returns \a str as a \c{const char *}. This is equivalent to - \a{str}.toLocal8Bit().constData(). + \a{str}.toLocal8Bit().\l{QByteArray::}{constData()}. The char pointer will be invalid after the statement in which qPrintable() is used. This is because the array returned by @@ -10292,7 +10293,7 @@ void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out) noe \since 5.4 Returns \a str as a \c{const char *}. This is equivalent to - \a{str}.toUtf8().constData(). + \a{str}.toUtf8().\l{QByteArray::}{constData()}. The char pointer will be invalid after the statement in which qUtf8Printable() is used. This is because the array returned by