Obsolete Members for QGlobalStatic

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

公共函数

(deprecated) QGlobalStatic<Holder>::Type *operator()()

(deprecated) Q_GLOBAL_STATIC_WITH_ARGS(Type, variableName, Arguments)

成员函数文档

[deprecated] QGlobalStatic<Holder>::Type *QGlobalStatic::operator()()

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

该函数返回全局静态内容的地址。如果内容尚未创建,则将由该函数以线程安全方式创建。如果内容已被销毁,该函数将返回一个空指针。

该函数等同于operator Type *() 。提供该函数是为了与 Qt XML 4.x 和 5.0 中的私有Q_GLOBAL_STATIC 实现兼容。新代码应避免使用该函数,而应将对象视为智能指针。

宏文档

[deprecated] Q_GLOBAL_STATIC_WITH_ARGS(Type, variableName, Arguments)

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

创建一个全局静态对象,类型为QGlobalStatic ,名称为variableName ,由参数Arguments 初始化,并作为指向Type 的指针。Q_GLOBAL_STATIC_WITH_ARGS 创建的对象在首次使用时初始化,这意味着它不会增加应用程序或库的加载时间。此外,该对象在所有平台上都是以线程安全的方式初始化的。

该宏在全局上下文(即不在任何函数或类体内部)中的典型用法如下:

Q_GLOBAL_STATIC_WITH_ARGS(MyType, myGlobal, (42, "Hello", "World"))

Arguments 宏参数必须始终用括号括起来,如果 C++11 允许统一初始化,则必须用大括号括起来。上述调用等价于

Q_GLOBAL_STATIC(MyType, myGlobal, 42, "Hello", "World")

除了需要将提供的参数括起来外,该宏的行为与Q_GLOBAL_STATIC() 相同。更多信息请参见该宏的文档。

另请参见 Q_GLOBAL_STATIC() 和QGlobalStatic

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