summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qapplicationstatic.qdoc
blob: 4d203a78aec8fba25b2b2a27110c54a55f0cabdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \macro Q_APPLICATION_STATIC(Type, VariableName)
    \since 6.3
    \relates QGlobalStatic

    This macro extends Q_GLOBAL_STATIC and creates a global and static object
    of type \l QGlobalStatic, of name \a VariableName and that behaves as a
    pointer to \a Type, where the actual lifetime of the type is bound to the
    QCoreApplication. The object created by Q_APPLICATION_STATIC initializes
    itself on the first use, which means that it will not increase the application
    or the library's load time. Additionally, the object is initialized in a
    thread-safe manner on all platforms.

    In contrast to Q_GLOBAL_STATIC where the type is only meant to be destroyed at
    program exit, here the actual lifetime of the type is bound to the lifetime of
    the QCoreApplication. This makes it ideal to store semi-static QObjects, which
    should also be destroyed once the QCoreApplication is destroyed. This means the
    type will get deleted once the QCoreApplication emits the destroyed signal.
    However, as long as the actual holder is still in the initialized state, the
    type will be recreated when it's accessed again once a new QCoreApplication
    has been created.

    Since the value is bound to the QCoreApplication it should only ever be accessed,
    if there is a valid QCoreApplication::instance().

    The typical use of this macro is as follows, in a global context (that is,
    outside of any function bodies):

    \code
        Q_APPLICATION_STATIC(MyQObjectType, staticType)
    \endcode

    Aside from the value also being bound to the lifetime of the QCoreApplication,
    this macro behaves identically to Q_GLOBAL_STATIC(). Please see that macro's
    documentation for more information.

    \sa Q_APPLICATION_STATIC_WITH_ARGS(), QGlobalStatic
*/

/*!
    \macro Q_APPLICATION_STATIC_WITH_ARGS(Type, VariableName, Arguments)
    \since 6.3
    \relates QGlobalStatic

    Creates a global and static object of type \l QGlobalStatic, of name \a
    VariableName, initialized by the arguments \a Arguments and that behaves as
    a pointer to \a Type, where the actual lifetime of the type is bound to the
    QCoreApplication. The object created by Q_APPLICATION_STATIC_WITH_ARGS
    initializes itself on the first use, which means that it will not increase
    the application or the library's load time. Additionally, the object is
    initialized in a thread-safe manner on all platforms.

    Since the value is bound to the QCoreApplication it should only ever be accessed,
    if there is a valid QCoreApplication::instance().

    The typical use of this macro is as follows, in a global context (that is,
    outside of any function bodies):

    \code
        Q_APPLICATION_STATIC_WITH_ARGS(MyQObjectType, staticType, (42, "Hello", "World"))
    \endcode

    The \a Arguments macro parameter must always include the parentheses or, if
    C++11 uniform initialization is allowed, the braces.

    Aside from the actual initialization of the contents with the supplied
    arguments, this macro behaves identically to Q_APPLICATION_STATIC(). Please
    see that macro's documentation for more information.

    \sa Q_APPLICATION_STATIC(), QGlobalStatic
*/