Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qcoreapplication.h
Go to the documentation of this file.
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_H
5#define QCOREAPPLICATION_H
6
7#include <QtCore/qglobal.h>
8#include <QtCore/qstring.h>
9#ifndef QT_NO_QOBJECT
10#include <QtCore/qcoreevent.h>
11#include <QtCore/qdeadlinetimer.h>
12#include <QtCore/qeventloop.h>
13#include <QtCore/qobject.h>
14#else
15#include <QtCore/qscopedpointer.h>
16#endif
17#include <QtCore/qnativeinterface.h>
18#ifndef QT_NO_DEBUGSTREAM
19#include <QtCore/qdebug.h>
20#endif
21
22#ifndef QT_NO_QOBJECT
23#if defined(Q_OS_WIN) && !defined(tagMSG)
24typedef struct tagMSG MSG;
25#endif
26#endif
27
29
30
32class QTranslator;
33class QPostEventList;
37
38#if QT_CONFIG(permissions) || defined(Q_QDOC)
39class QPermission;
40#endif
41
42#define qApp QCoreApplication::instance()
43
44class Q_CORE_EXPORT QCoreApplication
45#ifndef QT_NO_QOBJECT
46 : public QObject
47#endif
48{
49#ifndef QT_NO_QOBJECT
51 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName
52 NOTIFY applicationNameChanged)
53 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion
54 NOTIFY applicationVersionChanged)
55 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName
56 NOTIFY organizationNameChanged)
57 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain
58 NOTIFY organizationDomainChanged)
59 Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
60#endif
61
62 Q_DECLARE_PRIVATE(QCoreApplication)
63 friend class QEventLoopLocker;
64public:
65 enum { ApplicationFlags = QT_VERSION
66 };
67
68 QCoreApplication(int &argc, char **argv
69#ifndef Q_QDOC
70 , int = ApplicationFlags
71#endif
72 );
73
75
76 static QStringList arguments();
77
78 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
79 static bool testAttribute(Qt::ApplicationAttribute attribute);
80
81 static void setOrganizationDomain(const QString &orgDomain);
83 static void setOrganizationName(const QString &orgName);
85 static void setApplicationName(const QString &application);
87 static void setApplicationVersion(const QString &version);
89
90 static void setSetuidAllowed(bool allow);
91 static bool isSetuidAllowed();
92
93 static QCoreApplication *instance() noexcept { return self; }
94
95#ifndef QT_NO_QOBJECT
96 static int exec();
97 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
98 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
99 static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline);
100
101 static bool sendEvent(QObject *receiver, QEvent *event);
102 static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
103 static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
104 static void removePostedEvents(QObject *receiver, int eventType = 0);
105 static QAbstractEventDispatcher *eventDispatcher();
106 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
107
108 virtual bool notify(QObject *, QEvent *);
109
110 static bool startingUp();
111 static bool closingDown();
112#endif
113
114 static QString applicationDirPath();
115 static QString applicationFilePath();
116 static qint64 applicationPid() Q_DECL_CONST_FUNCTION;
117
118#if QT_CONFIG(permissions) || defined(Q_QDOC)
119 Qt::PermissionStatus checkPermission(const QPermission &permission);
120
121# ifdef Q_QDOC
122 template <typename Functor>
123 void requestPermission(const QPermission &permission, const QObject *context, Functor functor);
124# else
125 // requestPermission with context or receiver object; need to require here that receiver is the
126 // right type to avoid ambiguity with the private implementation function.
127 template <typename Functor>
128 void requestPermission(const QPermission &permission,
130 Functor &&func)
131 {
132 using Prototype = void(*)(QPermission);
133 QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
134 requestPermission(permission,
135 QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
136 receiver);
137 }
138# endif // Q_QDOC
139
140 // requestPermission to a functor or function pointer (without context)
141 template <typename Functor>
142 void requestPermission(const QPermission &permission, Functor &&func)
143 {
144 requestPermission(permission, nullptr, std::forward<Functor>(func));
145 }
146
147private:
148 // ### Qt 7: rename to requestPermissionImpl to avoid ambiguity
149 void requestPermission(const QPermission &permission,
151public:
152
153#endif // QT_CONFIG(permission)
154
155#if QT_CONFIG(library)
156 static void setLibraryPaths(const QStringList &);
157 static QStringList libraryPaths();
158 static void addLibraryPath(const QString &);
159 static void removeLibraryPath(const QString &);
160#endif // QT_CONFIG(library)
161
162#ifndef QT_NO_TRANSLATION
163 static bool installTranslator(QTranslator * messageFile);
164 static bool removeTranslator(QTranslator * messageFile);
165#endif
166
167 static QString translate(const char * context,
168 const char * key,
169 const char * disambiguation = nullptr,
170 int n = -1);
171
173
174#ifndef QT_NO_QOBJECT
175 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
176 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
177
178 static bool isQuitLockEnabled();
179 static void setQuitLockEnabled(bool enabled);
180
181public Q_SLOTS:
182 static void quit();
183 static void exit(int retcode = 0);
184
186 void aboutToQuit(QPrivateSignal);
187
192
193protected:
194 bool event(QEvent *) override;
195
196 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
197#endif // QT_NO_QOBJECT
198
199protected:
201
202#ifdef QT_NO_QOBJECT
204#endif
205
206private:
207#ifndef QT_NO_QOBJECT
208 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
209 static bool notifyInternal2(QObject *receiver, QEvent *);
210 static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
211#endif
212#if QT_CONFIG(library)
213 static QStringList libraryPathsLocked();
214#endif
215
216 static QCoreApplication *self;
217
218 Q_DISABLE_COPY(QCoreApplication)
219
220 friend class QApplication;
222 friend class QGuiApplication;
224 friend class QWidget;
225 friend class QWidgetWindow;
226 friend class QWidgetPrivate;
227#ifndef QT_NO_QOBJECT
231#endif
232 friend Q_CORE_EXPORT QString qAppName();
234};
235
236#define Q_DECLARE_TR_FUNCTIONS(context) \
237public: \
238 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
239 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
240private:
241
244
245Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
246Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
247Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
248Q_CORE_EXPORT QString qAppName(); // get application name
249
250#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
251 static void AFUNC ## _ctor_function() { \
252 qAddPreRoutine(AFUNC); \
253 } \
254 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
255
256#ifndef QT_NO_QOBJECT
257#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
258Q_CORE_EXPORT QString decodeMSG(const MSG &);
259Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
260#endif
261#endif
262
264
265#include <QtCore/qcoreapplication_platform.h>
266
267#endif // QCOREAPPLICATION_H
The QApplication class manages the GUI application's control flow and main settings.
\inmodule QtCore
void organizationDomainChanged()
static QString organizationDomain()
void applicationNameChanged()
static QString applicationVersion()
void organizationNameChanged()
static QString organizationName()
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
void aboutToQuit(QPrivateSignal)
This signal is emitted when the application is about to quit the main event loop, e....
static QString applicationName()
void applicationVersionChanged()
friend bool qt_sendSpontaneousEvent(QObject *, QEvent *)
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qeventloop.h:59
\inmodule QtCore
Definition qcoreevent.h:45
\macro qGuiApp
\inmodule QtCore
Definition qobject.h:90
friend class QCoreApplication
Definition qobject.h:345
QScopedPointer< QObjectData > d_ptr
Definition qobject.h:338
\inmodule QtCore \inheaderfile QPermissions
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qtranslator.h:19
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QList< QVariant > arguments
void requestPermission(const QPermission &permission, const PermissionCallback &callback)
Combined button and popup list for selecting options.
PermissionStatus
ApplicationAttribute
Definition qnamespace.h:423
@ NormalEventPriority
static void * context
#define Q_DECL_CONST_FUNCTION
QString qAppName()
static Q_CONSTINIT bool quitLockEnabled
Q_CORE_EXPORT QString qAppName()
void(* QtCleanUpFunction)()
void(* QtStartUpFunction)()
Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction)
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction)
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint attribute
#define QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(T)
GLuint64 key
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
GLfloat n
struct _cl_event * event
GLenum func
Definition qopenglext.h:663
GLfloat GLfloat p
[1]
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
#define QT_VERSION
long long qint64
Definition qtypes.h:55
struct tagMSG MSG
static bool translate(xcb_connection_t *connection, xcb_window_t child, xcb_window_t parent, int *x, int *y)
QDeadlineTimer deadline(30s)
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
dialog exec()
app setAttribute(Qt::AA_DontShowIconsInMenus)