Skip to content

Commit

Permalink
Relax use of QT_NO_CAST_FROM_ASCII to QT_RESTRICTED_CAST_FROM_ASCII
Browse files Browse the repository at this point in the history
This is an opt-in trade-off between type safety and user
code convenience.

QT_NO_CAST_FROM_ASCII is highly beneficial to avoid unintended
conversions from 8 bit data with potentially "unsuitable"
encodings to QString. However, it has the undesirable side-effect
to require user code to wrap character and string literals
in QLatin1Char(...) and QLatin1String(...) or use similar
construction, cluttering the code significantly.

QT_RESTRICTED_CAST_FROM_ASCII macro works almost as
QT_NO_CAST_FROM_ASCII, except that it enables the QChar(char)
constructor and adds an additional QString(const char (&ch)[N])
constructor that matches C++ string literals, but no arbitrary
character pointers.

This avoids a significant share of the need to clutter the
user code by only a slight relaxation of the type-safety.

Change-Id: I64e0430bb1352edcedf7e19ee25c16408727084c
Reviewed-by: Orgad Shaneh <[email protected]>
Reviewed-by: Eike Ziller <[email protected]>
  • Loading branch information
hjk committed Mar 17, 2016
1 parent 05fbef7 commit 82a523f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qtcreator.pri
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ exists($$IDE_LIBRARY_PATH): LIBS *= -L$$IDE_LIBRARY_PATH # library path from ou
DEFINES += IDE_LIBRARY_BASENAME=\\\"$$IDE_LIBRARY_BASENAME\\\"
}

DEFINES += QT_CREATOR QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
DEFINES += QT_CREATOR QT_NO_CAST_TO_ASCII QT_RESTRICTED_CAST_FROM_ASCII
!macx:DEFINES += QT_USE_FAST_OPERATOR_PLUS QT_USE_FAST_CONCATENATION

unix {
Expand Down
2 changes: 1 addition & 1 deletion qtcreator.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Project {
"QT_CREATOR",
'IDE_LIBRARY_BASENAME="' + libDirName + '"',
"QT_NO_CAST_TO_ASCII",
"QT_NO_CAST_FROM_ASCII"
"QT_RESTRICTED_CAST_FROM_ASCII"
].concat(testsEnabled ? ["WITH_TESTS"] : [])
qbsSearchPaths: "qbs"

Expand Down

0 comments on commit 82a523f

Please sign in to comment.