Qt::Literals::StringLiterals Namespace
namespace Qt::Literals::StringLiteralsStringLiterals 名前空間は、Qt の文字列型に対するリテラル演算子を定義しています。詳細...
| ヘッダー: | #include <QString> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
機能
(since 6.4) QLatin1Char | operator""_L1(char ch) |
(since 6.4) QLatin1StringView | operator""_L1(const char *str, size_t size) |
(since 6.4) QByteArray | operator""_ba(const char *str, size_t size) |
(since 6.4) QString | operator""_s(const char16_t *str, size_t size) |
詳細な説明
インラインのQt::Literals::StringLiterals 名前空間は、Qtの文字列型に対するリテラル演算子を宣言します。Literals と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 XMLがQt::Literals 内の異なる名前空間に競合する演算子を追加した場合、どのリテラル演算子を使用するかを指定できなくなるためです。
関数のドキュメント
[constexpr noexcept, since 6.4] QLatin1Char operator""_L1(char ch)
ch からQLatin1Char を作成するリテラル演算子。
以下のコードは、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)
文字リテラルstr の先頭からsize 文字分を取り出し、QLatin1StringView を作成するリテラル演算子です。
次のコードは、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)
文字列リテラル `str` の先頭 `size ` 文字から `QByteArray ` を作成するリテラル演算子です。
QByteArray はコンパイル時に生成され、生成された文字列データはコンパイル済みオブジェクトファイルの読み取り専用セグメントに格納されます。重複するリテラルは、同じ読み取り専用メモリを共有する場合があります。この機能はQByteArrayLiteral と互換性がありますが、コード内に多くの文字列リテラルが存在する場合、入力の手間を省くことができます。
以下のコードは、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)
char16_t型の文字列リテラルstr の先頭size 文字からQString を生成するリテラル演算子です。
QString はコンパイル時に生成され、生成された文字列データはコンパイル済みオブジェクトファイルの読み取り専用セグメントに格納されます。重複するリテラルは、同じ読み取り専用メモリを共有する場合があります。この機能はQStringLiteral と同等の動作をしますが、コード内に多くの文字列リテラルが存在する場合、入力の手間を省くことができます。
以下のコードは、QString を作成します:
using namespace Qt::StringLiterals;
auto str = u"hello"_s;この関数は Qt 6.4 で導入されました。
Qt::Literals::StringLiteralsも参照してください 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.