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