StringLiterals Namespace

Qt::Literals::StringLiterals

StringLiterals 名前空間は、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)

詳細な説明

inlineQt::Literals::StringLiterals 名前空間は Qt 型の文字列リテラル演算子を宣言します。LiteralsStringLiterals の両方の名前空間がインラインとして宣言されているため、以下のいずれかをコードに追加することで、この名前空間のシンボルにアクセスできます:

// Makes visible only the literal operators declared in StringLiterals
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;

関数ドキュメント

[constexpr noexcept, since 6.4] QLatin1Char operator""_L1(char ch)

ch からQLatin1Char を生成するリテラル演算子。

次のコードはQLatin1Char を作成します:

using namespace Qt::Literals::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::Literals::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::Literals::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::Literals::StringLiterals;

auto str = u"hello"_s;

この関数は Qt 6.4 で導入されました。

Qt::Literals::StringLiteralsも参照してください

© 2025 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.