The StringLiterals namespace declares literal operators for Qt string types. 更多...
| 頭: |
#include <QString>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
|
| qmake: |
QT += core
|
(從 6.4 起)
QLatin1Char
|
operator""_L1 (char ch ) |
(從 6.4 起)
QLatin1StringView
|
operator""_L1 (const char * str , size_t size ) |
(從 6.4 起)
QByteArray
|
operator""_ba (const char * str , size_t size ) |
(從 6.4 起)
QString
|
operator""_s (const char16_t * str , size_t size ) |
內聯
Qt::Literals::StringLiterals
名稱空間聲明用於 Qt 字符串類型的文字操作符。因為兩者
Literals
and
StringLiterals
名稱空間是以內聯方式聲明的,所以,來自此名稱空間的符號可以通過在代碼中添加下列之一訪問:
// Makes visible only the literal operators declared in StringLiterals using namespace Qt::StringLiterals; // same, but needlessly verbose: using namespace Qt::Literals::StringLiterals; // Makes visible literal operators declared in all inline namespaces // inside Literals using namespace Qt::Literals; // Makes visible all symbols (including all literal operators) declared // in the Qt namespace using namespace Qt;
後者不受鼓勵,因為它不允許拾取想要的字麵操作符,以防 Qt 在不同命名空間添加衝突操作符按 Qt::Literals .
[constexpr noexcept, since 6.4]
QLatin1Char
operator""_L1
(
char
ch
)
文字運算符創建的 QLatin1Char out of ch .
以下代碼創建 QLatin1Char :
using namespace Qt::StringLiterals; auto ch = 'a'_L1;
該函數在 Qt 6.4 引入。
另請參閱 Qt::Literals::StringLiterals .
[constexpr noexcept, since 6.4]
QLatin1StringView
operator""_L1
(const
char
*
str
,
size_t
size
)
文字運算符創建的 QLatin1StringView out of the first size characters in the char string literal str .
以下代碼創建 QLatin1StringView :
using namespace Qt::StringLiterals; auto str = "hello"_L1;
該函數在 Qt 6.4 引入。
另請參閱 Qt::Literals::StringLiterals .
[noexcept, since 6.4]
QByteArray
operator""_ba
(const
char
*
str
,
size_t
size
)
文字運算符創建的 QByteArray out of the first size characters in the char string literal str .
The QByteArray is created at compile time, and the generated string data is stored in the read-only segment of the compiled object file. Duplicate literals may share the same read-only memory. This functionality is interchangeable with QByteArrayLiteral , but saves typing when many string literals are present in the code.
以下代碼創建 QByteArray :
using namespace Qt::StringLiterals; auto str = "hello"_ba;
該函數在 Qt 6.4 引入。
另請參閱 Qt::Literals::StringLiterals .
[noexcept, since 6.4]
QString
operator""_s
(const
char16_t
*
str
,
size_t
size
)
文字運算符創建的 QString out of the first size characters in the char16_t string literal str .
The QString is created at compile time, and the generated string data is stored in the read-only segment of the compiled object file. Duplicate literals may share the same read-only memory. This functionality is interchangeable with QStringLiteral , but saves typing when many string literals are present in the code.
以下代碼創建 QString :
using namespace Qt::StringLiterals; auto str = u"hello"_s;
該函數在 Qt 6.4 引入。
另請參閱 Qt::Literals::StringLiterals .