Obsolete Members for QObject

QObject 的以下成员已被弃用。提供这些成员是为了保持旧源代码的正常运行。我们强烈建议不要在新代码中使用它们。

(deprecated) Q_ENUMS(...)
(deprecated) Q_FLAGS(...)

宏文档

[deprecated] Q_ENUMS(...)

该宏已被弃用。我们强烈建议不要在新代码中使用它。

在新代码中,您应优先使用Q_ENUM() 宏,它可使元类型系统也能使用该类型。例如,QMetaEnum::fromType() 对使用 Q_ENUMS() 声明的类型不起作用。

该宏向元对象系统注册一个或多个枚举类型。

如果要注册一个在其他类中声明的枚举类型,则必须用定义该枚举类型的类的名称来完全限定该枚举类型。此外,定义枚举的类必须继承QObject 并使用 Q_ENUMS() 声明枚举。

另请参阅 Qt 的属性系统

[deprecated] Q_FLAGS(...)

该宏已被弃用。我们强烈建议不要在新代码中使用它。

该宏用于在元对象系统中注册一个或多个flags types 。它通常用于类定义中,以声明给定枚举的值可用作标志,并使用比特 OR 运算符进行组合。

注意: 该宏负责在元对象系统中注册单个标志值,因此除了该宏之外,没有必要使用Q_ENUMS() 。

在新代码中,您应优先使用Q_FLAG() 宏,因为该宏能使元类型系统也能使用该类型。

另请参阅 Qt 的属性系统

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