在本页

Qt::Literals Namespace

namespace Qt::Literals

Literals 内联命名空间声明了 Qt 类型的字面运算符。更多

头文件: #include <QString>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

命名空间

namespace StringLiterals

详细说明

命名空间

namespace Literals::StringLiterals

内联Qt::Literals::StringLiterals 命名空间声明了 Qt 字符串类型的字面运算符。由于LiteralsStringLiterals 命名空间都声明为内联,因此可以通过在代码中添加以下一种方法来访问该命名空间中的符号:

// 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 内的不同命名空间中添加了相互冲突的运算符时,您无法选择需要的字面运算符。

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