Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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;
64#if QT_CONFIG(permissions)
65 using RequestPermissionPrototype = void(*)(QPermission);
66#endif
67
68public:
69 enum { ApplicationFlags = QT_VERSION
70 };
71
72 QCoreApplication(int &argc, char **argv
73#ifndef Q_QDOC
74 , int = ApplicationFlags
75#endif
76 );
77
79
80 static QStringList arguments();
81
82 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
83 static bool testAttribute(Qt::ApplicationAttribute attribute);
84
85 static void setOrganizationDomain(const QString &orgDomain);
87 static void setOrganizationName(const QString &orgName);
89 static void setApplicationName(const QString &application);
91 static void setApplicationVersion(const QString &version);
93
94 static void setSetuidAllowed(bool allow);
95 static bool isSetuidAllowed();
96
97 static QCoreApplication *instance() noexcept { return self; }
98
99#ifndef QT_NO_QOBJECT
100 static int exec();
101 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
102 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
103 static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline);
104
105 static bool sendEvent(QObject *receiver, QEvent *event);
106 static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
107 static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
108 static void removePostedEvents(QObject *receiver, int eventType = 0);
109 static QAbstractEventDispatcher *eventDispatcher();
110 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
111
112 virtual bool notify(QObject *, QEvent *);
113
114 static bool startingUp();
115 static bool closingDown();
116#endif
117
118 static QString applicationDirPath();
119 static QString applicationFilePath();
120 static qint64 applicationPid() Q_DECL_CONST_FUNCTION;
121
122#if QT_CONFIG(permissions) || defined(Q_QDOC)
123 Qt::PermissionStatus checkPermission(const QPermission &permission);
124
125# ifdef Q_QDOC
126 template <typename Functor>
127 void requestPermission(const QPermission &permission, const QObject *context, Functor functor);
128# else
129 // requestPermission with context or receiver object; need to require here that receiver is the
130 // right type to avoid ambiguity with the private implementation function.
131 template <typename Functor,
132 std::enable_if_t<
134 bool> = true>
135 void requestPermission(const QPermission &permission,
137 Functor &&func)
138 {
139 requestPermission(permission,
140 QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)),
141 receiver);
142 }
143# endif // Q_QDOC
144
145#ifndef QT_NO_CONTEXTLESS_CONNECT
146 #ifdef Q_QDOC
147 template <typename Functor>
148 #else
149 // requestPermission to a functor or function pointer (without context)
150 template <typename Functor,
151 std::enable_if_t<
153 bool> = true>
154 #endif
155 void requestPermission(const QPermission &permission, Functor &&func)
156 {
157 requestPermission(permission, nullptr, std::forward<Functor>(func));
158 }
159#endif // QT_NO_CONTEXTLESS_CONNECT
160
161private:
162 // ### Qt 7: rename to requestPermissionImpl to avoid ambiguity
163 void requestPermission(const QPermission &permission,
165public:
166
167#endif // QT_CONFIG(permission)
168
169#if QT_CONFIG(library)
170 static void setLibraryPaths(const QStringList &);
171 static QStringList libraryPaths();
172 static void addLibraryPath(const QString &);
173 static void removeLibraryPath(const QString &);
174#endif // QT_CONFIG(library)
175
176#ifndef QT_NO_TRANSLATION
177 static bool installTranslator(QTranslator * messageFile);
178 static bool removeTranslator(QTranslator * messageFile);
179#endif
180
181 static QString translate(const char * context,
182 const char * key,
183 const char * disambiguation = nullptr,
184 int n = -1);
185
187
188#ifndef QT_NO_QOBJECT
189 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
190 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
191
192 static bool isQuitLockEnabled();
193 static void setQuitLockEnabled(bool enabled);
194
195public Q_SLOTS:
196 static void quit();
197 static void exit(int retcode = 0);
198
200 void aboutToQuit(QPrivateSignal);
201
206
207protected:
208 bool event(QEvent *) override;
209
210 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
211#endif // QT_NO_QOBJECT
212
213protected:
215
216#ifdef QT_NO_QOBJECT
217 QScopedPointer<QCoreApplicationPrivate> d_ptr;
218#endif
219
220private:
221#ifndef QT_NO_QOBJECT
222 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
223 static bool notifyInternal2(QObject *receiver, QEvent *);
224 static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
225#endif
226#if QT_CONFIG(library)
227 static QStringList libraryPathsLocked();
228#endif
229
230 static QCoreApplication *self;
231
232 Q_DISABLE_COPY(QCoreApplication)
233
234 friend class QApplication;
236 friend class QGuiApplication;
238 friend class QWidget;
239 friend class QWidgetWindow;
240 friend class QWidgetPrivate;
241#ifndef QT_NO_QOBJECT
245#endif
246 friend Q_CORE_EXPORT QString qAppName();
248};
249
250#define Q_DECLARE_TR_FUNCTIONS(context) \
251public: \
252 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
253 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
254private:
255
258
259Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
260Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
261Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
262Q_CORE_EXPORT QString qAppName(); // get application name
263
264#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
265 static void AFUNC ## _ctor_function() { \
266 qAddPreRoutine(AFUNC); \
267 } \
268 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
269
270#ifndef QT_NO_QOBJECT
271#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
272Q_CORE_EXPORT QString decodeMSG(const MSG &);
273Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
274#endif
275#endif
276
278
279#include <QtCore/qcoreapplication_platform.h>
280
281#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:103
\inmodule QtCore \inheaderfile QPermissions
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\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:424
@ 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:60
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)