summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2020-11-24 16:06:12 +0100
committerKai Koehne <kai.koehne@qt.io>2020-12-04 12:25:51 +0100
commit9c53de10f730f287c74b3de83295cc88b7767bf8 (patch)
treea5404bf6ab5b831802916aa748b07deb7c7724e7
parent1fa5245b274fb37cbadd99a6adb2ebbcae038a10 (diff)
Doc: Improve *_CAST_FROM_ASCII documentation
Change-Id: Iba73c0a38e2c4add740aab20036aa39c56eb4d98 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit 50873153a70521e138b590a227902876f998270e)
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp6
-rw-r--r--src/corelib/text/qstring.cpp23
2 files changed, 9 insertions, 20 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp
index 4e79d1e27a..fade47cfc6 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qstring.cpp
@@ -48,12 +48,6 @@
**
****************************************************************************/
-//! [0]
-DEFINES += QT_NO_CAST_FROM_ASCII \
- QT_NO_CAST_TO_ASCII
-//! [0]
-
-
//! [1]
QString url = QLatin1String("http://www.unicode.org/");
//! [1]
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 5715804444..d18d8ec89b 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -1331,11 +1331,11 @@ const QString::Null QString::null = { };
\macro QT_RESTRICTED_CAST_FROM_ASCII
\relates QString
- Defining this macro disables most automatic conversions from source
- literals and 8-bit data to unicode QStrings, but allows the use of
+ Disables most automatic conversions from source literals and 8-bit data
+ to unicode QStrings, but allows the use of
the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors,
- 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
+ and the \c{QString::operator=(const char (&ch)[N])} assignment operator.
+ 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
with QLatin1Char, QLatin1String or similar.
@@ -1358,7 +1358,7 @@ const QString::Null QString::null = { };
\macro QT_NO_CAST_TO_ASCII
\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
*/
@@ -1616,23 +1616,18 @@ const QString::Null QString::null = { };
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
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
- \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.
- \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
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.
\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_tools_qstring.cpp 0
-
You then need to explicitly call fromUtf8(), fromLatin1(),
or fromLocal8Bit() to construct a QString from an
8-bit string, or use the lightweight QLatin1String class, for