[docs] QString: fix link and formatting in the qPrintable() discussion

The old code used a `<QString>` 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
<QString>.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 <edward.welbourne@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2025-03-07 15:57:00 +01:00
parent b83f104889
commit ab1ce95c8c

View File

@ -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 <QString>.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