1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOREAPPLICATION_P_H
5#define QCOREAPPLICATION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "QtCore/qcoreapplication.h"
19#if QT_CONFIG(commandlineparser)
20#include "QtCore/qcommandlineoption.h"
21#endif
22#include "QtCore/qreadwritelock.h"
23#include "QtCore/qtranslator.h"
24#ifndef QT_NO_QOBJECT
25#include "private/qobject_p.h"
26#include "private/qlocking_p.h"
27#endif
28
29#ifdef Q_OS_MACOS
30#include "private/qcore_mac_p.h"
31#endif
32
33QT_BEGIN_NAMESPACE
34
35typedef QList<QTranslator*> QTranslatorList;
36
37class QAbstractEventDispatcher;
38
39#ifndef QT_NO_QOBJECT
40class QEvent;
41#endif
42
43class Q_CORE_EXPORT QCoreApplicationPrivate
44#ifndef QT_NO_QOBJECT
45 : public QObjectPrivate
46#endif
47{
48 Q_DECLARE_PUBLIC(QCoreApplication)
49
50public:
51 enum Type : quint8 {
52 Tty,
53 Gui
54 };
55
56 QCoreApplicationPrivate(int &aargc, char **aargv);
57
58 // If not inheriting from QObjectPrivate: force this class to be polymorphic
59#ifdef QT_NO_QOBJECT
60 virtual
61#endif
62 ~QCoreApplicationPrivate();
63
64 void init();
65
66 QString appName() const;
67 QString appVersion() const;
68
69#ifdef Q_OS_DARWIN
70 static QString infoDictionaryStringProperty(const QString &propertyName);
71#endif
72
73#ifdef Q_OS_WINDOWS
74 void initDebuggingConsole();
75 void cleanupDebuggingConsole();
76#endif
77 static void initLocale();
78
79 static bool checkInstance(const char *method);
80
81#if QT_CONFIG(commandlineparser)
82 virtual void addQtOptions(QList<QCommandLineOption> *options);
83#endif
84
85#ifndef QT_NO_QOBJECT
86 bool sendThroughApplicationEventFilters(QObject *, QEvent *);
87 static bool sendThroughObjectEventFilters(QObject *, QEvent *);
88 static bool notify_helper(QObject *, QEvent *);
89 static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->m_spont = spontaneous; }
90
91 virtual void createEventDispatcher();
92 virtual void eventDispatcherReady();
93 virtual bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents);
94 static void removePostedEvent(QEvent *);
95#ifdef Q_OS_WIN
96 static void removePostedTimerEvent(QObject *object, int timerId);
97#endif
98
99 QAtomicInt quitLockRef;
100 void ref();
101 void deref();
102 virtual bool canQuitAutomatically();
103 void quitAutomatically();
104 virtual void quit();
105
106 static QBasicAtomicPointer<QThread> theMainThread;
107 static QBasicAtomicPointer<void> theMainThreadId;
108 static QThread *mainThread();
109
110 static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
111
112 static void checkReceiverThread(QObject *receiver);
113 void cleanupThreadData();
114
115 struct QPostEventListLocker
116 {
117 QThreadData *threadData;
118 std::unique_lock<QMutex> locker;
119
120 void unlock() { locker.unlock(); }
121 };
122 static QPostEventListLocker lockThreadPostEventList(QObject *object);
123#endif // QT_NO_QOBJECT
124
125 int &argc;
126 char **argv;
127#if defined(Q_OS_WIN)
128 // store unmodified arguments for QCoreApplication::arguments()
129 int origArgc = 0;
130 std::unique_ptr<char *[]> origArgv;
131
132 bool consoleAllocated = false;
133 static void *mainInstanceHandle; // HINSTANCE without <windows.h>
134#endif
135
136 Type application_type = Tty;
137
138#ifndef QT_NO_QOBJECT
139 void execCleanup();
140
141 bool in_exec = false;
142 bool aboutToQuitEmitted = false;
143 bool threadData_clean = false;
144
145 static QAbstractEventDispatcher *eventDispatcher;
146 static bool is_app_running;
147 static bool is_app_closing;
148#endif
149#ifndef QT_NO_TRANSLATION
150 QTranslatorList translators;
151 QReadWriteLock translateMutex;
152 static bool isTranslatorInstalled(QTranslator *translator);
153#endif
154
155 static bool setuidAllowed;
156 static uint attribs;
157 static inline bool testAttribute(uint flag) { return attribs & (1 << flag); }
158
159 void processCommandLineArguments();
160 QString cachedApplicationFilePath;
161 QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging.
162 inline QString qmljsDebugArgumentsString() const { return qmljs_debug_arguments; }
163
164#ifdef QT_NO_QOBJECT
165 QCoreApplication *q_ptr = nullptr;
166#endif
167};
168
169QT_END_NAMESPACE
170
171#endif // QCOREAPPLICATION_P_H
172

source code of qtbase/src/corelib/kernel/qcoreapplication_p.h