Nesta página

Qt::Literals::StringLiterals Namespace

namespace Qt::Literals::StringLiterals

O namespace StringLiterals declara operadores literais para os tipos de string do Qt. Mais...

Cabeçalho: #include <QString>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

Funções

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

Descrição detalhada

O namespace inline Qt::Literals::StringLiterals declara operadores literais para os tipos de string do Qt. Como os namespaces Literals e StringLiterals são declarados como inline, os símbolos desse namespace podem ser acessados adicionando-se uma das seguintes opções ao seu código:

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

A última opção não é recomendada, pois não permite que você escolha quais operadores literais deseja, caso o Qt adicione operadores conflitantes em diferentes namespaces dentro de ` Qt::Literals`.

Documentação de funções

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

Operador literal que cria um ` QLatin1Char ` a partir de ` ch`.

O código a seguir cria um ` QLatin1Char`:

using namespace Qt::StringLiterals;

auto ch = 'a'_L1;

Esta função foi introduzida no Qt 6.4.

Veja também Qt::Literals::StringLiterals.

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

Operador literal que cria um ` QLatin1StringView ` a partir dos primeiros ` size ` caracteres da string literal de tipo `char` ` str`.

O código a seguir cria um ` QLatin1StringView`:

using namespace Qt::StringLiterals;

auto str = "hello"_L1;

Essa função foi introduzida no Qt 6.4.

Veja também Qt::Literals::StringLiterals.

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

Operador literal que cria um ` QByteArray ` a partir dos primeiros ` size ` caracteres da string literal de tipo `char` ` str`.

O QByteArray é criado em tempo de compilação, e os dados da string gerada são armazenados no segmento somente leitura do arquivo objeto compilado. Literais duplicados podem compartilhar a mesma memória somente leitura. Essa funcionalidade é intercambiável com QByteArrayLiteral, mas economiza digitação quando há muitos literais de string no código.

O código a seguir cria um ` QByteArray`:

using namespace Qt::StringLiterals;

auto str = "hello"_ba;

Essa função foi introduzida no Qt 6.4.

Veja também Qt::Literals::StringLiterals.

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

Operador literal que cria um ` QString ` a partir dos primeiros ` size ` caracteres do literal de string `char16_t` ` str`.

O ` QString ` é criado em tempo de compilação, e os dados da string gerada são armazenados no segmento somente leitura do arquivo objeto compilado. Literais duplicados podem compartilhar a mesma memória somente leitura. Essa funcionalidade é intercambiável com ` QStringLiteral`, mas economiza digitação quando há muitos literais de string no código.

O código a seguir cria um ` QString`:

using namespace Qt::StringLiterals;

auto str = u"hello"_s;

Essa função foi introduzida no Qt 6.4.

Veja também ` 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.