Qt::Literals::StringLiterals Namespace | Qt Core | Qt 6.11.0
Description: The StringLiterals namespace declares literal operators for Qt string types.

- Qt 6.11
- Qt Core
- Qt::Literals::StringLiterals Namespace
- Qt 6.11.0 Reference Documentation

# Qt::Literals::StringLiterals Namespace

namespace Qt::Literals::StringLiterals

The StringLiterals namespace declares literal operators for Qt string types. More...

Header: | `#include <QString>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`

## Functions

`(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)

## Detailed Description

The inline Qt::Literals::StringLiterals namespace declares literal operators for Qt string types. Because both `Literals` and `StringLiterals` namespaces are declared as inline, the symbols from this namespace can be accessed by adding one of the following to your code:

     // 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;

The latter is discouraged, because it doesn't allow you to pick which literal operators you want in case Qt adds conflicting operators in different namespaces within Qt::Literals.

## Function Documentation

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

Literal operator that creates a QLatin1Char out of ch.

The following code creates a QLatin1Char:

     using namespace Qt::StringLiterals;

     auto ch = 'a'_L1;

This function was introduced in Qt 6.4.

See also Qt::Literals::StringLiterals.

### `[constexpr noexcept, since 6.4]` QLatin1StringView operator""_L1(const char *str, size_t size)

Literal operator that creates a QLatin1StringView out of the first size characters in the char string literal str.

The following code creates a QLatin1StringView:

     using namespace Qt::StringLiterals;

     auto str = "hello"_L1;

This function was introduced in Qt 6.4.

See also Qt::Literals::StringLiterals.

### `[noexcept, since 6.4]` QByteArray operator""_ba(const char *str, size_t size)

Literal operator that creates a 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.

The following code creates a QByteArray:

     using namespace Qt::StringLiterals;

     auto str = "hello"_ba;

This function was introduced in Qt 6.4.

See also Qt::Literals::StringLiterals.

### `[noexcept, since 6.4]` QString operator""_s(const char16_t *str, size_t size)

Literal operator that creates a 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.

The following code creates a QString:

     using namespace Qt::StringLiterals;

     auto str = u"hello"_s;

This function was introduced in Qt 6.4.

See also Qt::Literals::StringLiterals.