Doc: Improve *_CAST_FROM_ASCII documentation

Change-Id: Iba73c0a38e2c4add740aab20036aa39c56eb4d98
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit 50873153a70521e138b590a227902876f998270e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Kai Koehne 2020-11-24 16:06:12 +01:00 committed by Qt Cherry-pick Bot
parent 3b58d9814f
commit 9481cb1fc6
2 changed files with 9 additions and 20 deletions

View File

@ -48,12 +48,6 @@
** **
****************************************************************************/ ****************************************************************************/
//! [0]
DEFINES += QT_NO_CAST_FROM_ASCII \
QT_NO_CAST_TO_ASCII
//! [0]
//! [1] //! [1]
QString url = QLatin1String("http://www.unicode.org/"); QString url = QLatin1String("http://www.unicode.org/");
//! [1] //! [1]

View File

@ -1492,11 +1492,11 @@ inline char qToLower(char ch)
\macro QT_RESTRICTED_CAST_FROM_ASCII \macro QT_RESTRICTED_CAST_FROM_ASCII
\relates QString \relates QString
Defining this macro disables most automatic conversions from source Disables most automatic conversions from source literals and 8-bit data
literals and 8-bit data to unicode QStrings, but allows the use of to unicode QStrings, but allows the use of
the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors, the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors,
and the \c{QString::operator=(const char (&ch)[N])} assignment operator and the \c{QString::operator=(const char (&ch)[N])} assignment operator.
giving most of the type-safety benefits of \c QT_NO_CAST_FROM_ASCII This gives most of the type-safety benefits of \c QT_NO_CAST_FROM_ASCII
but does not require user code to wrap character and string literals but does not require user code to wrap character and string literals
with QLatin1Char, QLatin1String or similar. with QLatin1Char, QLatin1String or similar.
@ -1521,7 +1521,7 @@ inline char qToLower(char ch)
\macro QT_NO_CAST_TO_ASCII \macro QT_NO_CAST_TO_ASCII
\relates QString \relates QString
disables automatic conversion from QString to 8-bit strings (char *) Disables automatic conversion from QString to 8-bit strings (char *).
\sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY \sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
*/ */
@ -1756,23 +1756,18 @@ inline char qToLower(char ch)
Latin-1, but there is always the risk that an implicit conversion Latin-1, but there is always the risk that an implicit conversion
from or to \c{const char *} is done using the wrong 8-bit from or to \c{const char *} is done using the wrong 8-bit
encoding. To minimize these risks, you can turn off these implicit encoding. To minimize these risks, you can turn off these implicit
conversions by defining the following two preprocessor symbols: conversions by defining some of the following preprocessor symbols:
\list \list
\li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from \li \l QT_NO_CAST_FROM_ASCII disables automatic conversions from
C string literals and pointers to Unicode. C string literals and pointers to Unicode.
\li \c QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions \li \l QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions
from C characters and character arrays, but disables automatic from C characters and character arrays, but disables automatic
conversions from character pointers to Unicode. conversions from character pointers to Unicode.
\li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString \li \l QT_NO_CAST_TO_ASCII disables automatic conversion from QString
to C strings. to C strings.
\endlist \endlist
One way to define these preprocessor symbols globally for your
application is to add the following entry to your \l {Creating Project Files}{qmake project file}:
\snippet code/src_corelib_text_qstring.cpp 0
You then need to explicitly call fromUtf8(), fromLatin1(), You then need to explicitly call fromUtf8(), fromLatin1(),
or fromLocal8Bit() to construct a QString from an or fromLocal8Bit() to construct a QString from an
8-bit string, or use the lightweight QLatin1String class, for 8-bit string, or use the lightweight QLatin1String class, for