File indexing completed on 2026-11-04 10:14:49
0001
0002
0003
0004
0005 #ifndef QCOREAPPLICATION_H
0006 #define QCOREAPPLICATION_H
0007
0008 #include <QtCore/qglobal.h>
0009 #include <QtCore/qstring.h>
0010 #ifndef QT_NO_QOBJECT
0011 #include <QtCore/qcoreevent.h>
0012 #include <QtCore/qdeadlinetimer.h>
0013 #include <QtCore/qeventloop.h>
0014 #include <QtCore/qobject.h>
0015 #else
0016 #include <QtCore/qscopedpointer.h>
0017 #endif
0018 #include <QtCore/qnativeinterface.h>
0019
0020 #ifndef QT_NO_QOBJECT
0021 #if defined(Q_OS_WIN) && !defined(tagMSG)
0022 typedef struct tagMSG MSG;
0023 #endif
0024 #endif
0025
0026 QT_BEGIN_NAMESPACE
0027
0028 class QAbstractEventDispatcher;
0029 class QAbstractNativeEventFilter;
0030 class QDebug;
0031 class QEventLoopLocker;
0032 class QPermission;
0033 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0034 class QPostEventList;
0035 #endif
0036 class QTranslator;
0037
0038 #define qApp QCoreApplication::instance()
0039
0040 class QCoreApplicationPrivate;
0041 class Q_CORE_EXPORT QCoreApplication
0042 #ifndef QT_NO_QOBJECT
0043 : public QObject
0044 #endif
0045 {
0046 #ifndef QT_NO_QOBJECT
0047 Q_OBJECT
0048 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName
0049 NOTIFY applicationNameChanged)
0050 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion
0051 NOTIFY applicationVersionChanged)
0052 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName
0053 NOTIFY organizationNameChanged)
0054 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain
0055 NOTIFY organizationDomainChanged)
0056 Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
0057 #endif
0058
0059 Q_DECLARE_PRIVATE(QCoreApplication)
0060 friend class QEventLoopLocker;
0061 #if QT_CONFIG(permissions)
0062 using RequestPermissionPrototype = void(*)(QPermission);
0063 #endif
0064
0065 public:
0066 enum { ApplicationFlags = QT_VERSION
0067 };
0068
0069 QCoreApplication(int &argc, char **argv
0070 #ifndef Q_QDOC
0071 , int = ApplicationFlags
0072 #endif
0073 );
0074
0075 ~QCoreApplication();
0076
0077 static QStringList arguments();
0078
0079 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
0080 static bool testAttribute(Qt::ApplicationAttribute attribute);
0081
0082 static void setOrganizationDomain(const QString &orgDomain);
0083 static QString organizationDomain();
0084 static void setOrganizationName(const QString &orgName);
0085 static QString organizationName();
0086 static void setApplicationName(const QString &application);
0087 static QString applicationName();
0088 static void setApplicationVersion(const QString &version);
0089 static QString applicationVersion();
0090
0091 static void setSetuidAllowed(bool allow);
0092 static bool isSetuidAllowed();
0093
0094 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0095 static QCoreApplication *instance() noexcept { return self.loadRelaxed(); }
0096 static bool instanceExists() noexcept { return instance() != nullptr; }
0097 #else
0098 # ifdef __cpp_lib_atomic_ref
0099 static QCoreApplication *instance() noexcept
0100 { return std::atomic_ref(self).load(std::memory_order_relaxed); }
0101 # else
0102 static QCoreApplication *instance() noexcept { return self; }
0103 # endif
0104 static bool instanceExists() noexcept;
0105 #endif
0106
0107 #ifndef QT_NO_QOBJECT
0108 static int exec();
0109 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
0110 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
0111 static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline);
0112
0113 static bool sendEvent(QObject *receiver, QEvent *event);
0114 static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
0115 static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
0116 static void removePostedEvents(QObject *receiver, int eventType = 0);
0117 static QAbstractEventDispatcher *eventDispatcher();
0118 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
0119
0120 virtual bool notify(QObject *, QEvent *);
0121
0122 static bool startingUp();
0123 static bool closingDown();
0124 #endif
0125
0126 static QString applicationDirPath();
0127 static QString applicationFilePath();
0128 Q_DECL_CONST_FUNCTION static qint64 applicationPid() noexcept;
0129
0130 #if QT_CONFIG(permissions) || defined(Q_QDOC)
0131 Qt::PermissionStatus checkPermission(const QPermission &permission);
0132
0133 # ifdef Q_QDOC
0134 template <typename Functor>
0135 void requestPermission(const QPermission &permission, const QObject *context, Functor functor);
0136 # else
0137
0138
0139 template <typename Functor,
0140 std::enable_if_t<
0141 QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value,
0142 bool> = true>
0143 void requestPermission(const QPermission &permission,
0144 const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver,
0145 Functor &&func)
0146 {
0147 requestPermissionImpl(permission,
0148 QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)),
0149 receiver);
0150 }
0151 # endif
0152
0153 #ifndef QT_NO_CONTEXTLESS_CONNECT
0154 #ifdef Q_QDOC
0155 template <typename Functor>
0156 #else
0157
0158 template <typename Functor,
0159 std::enable_if_t<
0160 QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value,
0161 bool> = true>
0162 #endif
0163 void requestPermission(const QPermission &permission, Functor &&func)
0164 {
0165 requestPermission(permission, nullptr, std::forward<Functor>(func));
0166 }
0167 #endif
0168
0169 #if QT_CORE_REMOVED_SINCE(6, 10)
0170 private:
0171 void requestPermission(const QPermission &permission,
0172 QtPrivate::QSlotObjectBase *slotObj, const QObject *context);
0173 public:
0174 #endif
0175
0176 #endif
0177
0178 #if QT_CONFIG(library)
0179 static void setLibraryPaths(const QStringList &);
0180 static QStringList libraryPaths();
0181 static void addLibraryPath(const QString &);
0182 static void removeLibraryPath(const QString &);
0183 #endif
0184
0185 #ifndef QT_NO_TRANSLATION
0186 static bool installTranslator(QTranslator * messageFile);
0187 static bool removeTranslator(QTranslator * messageFile);
0188 #endif
0189
0190 static QString translate(const char * context,
0191 const char * key,
0192 const char * disambiguation = nullptr,
0193 int n = -1);
0194
0195 QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QCoreApplication)
0196
0197 #ifndef QT_NO_QOBJECT
0198 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
0199 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
0200
0201 static bool isQuitLockEnabled();
0202 static void setQuitLockEnabled(bool enabled);
0203
0204 public Q_SLOTS:
0205 static void quit();
0206 static void exit(int retcode = 0);
0207
0208 Q_SIGNALS:
0209 void aboutToQuit(QPrivateSignal);
0210
0211 void organizationNameChanged();
0212 void organizationDomainChanged();
0213 void applicationNameChanged();
0214 void applicationVersionChanged();
0215
0216 protected:
0217 bool event(QEvent *) override;
0218
0219 # if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0220 QT_DEPRECATED_VERSION_X_6_10("This feature will be removed in Qt 7")
0221 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
0222 # endif
0223 #endif
0224
0225 protected:
0226 QCoreApplication(QCoreApplicationPrivate &p);
0227
0228 #ifdef QT_NO_QOBJECT
0229 std::unique_ptr<QCoreApplicationPrivate> d_ptr;
0230 #endif
0231
0232 private:
0233 #ifndef QT_NO_QOBJECT
0234 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
0235 static bool notifyInternal2(QObject *receiver, QEvent *);
0236 static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
0237
0238 void requestPermissionImpl(const QPermission &permission, QtPrivate::QSlotObjectBase *slotObj,
0239 const QObject *context);
0240 #endif
0241
0242 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0243 static QBasicAtomicPointer<QCoreApplication> self;
0244 #else
0245 static QCoreApplication *self;
0246 #endif
0247
0248 Q_DISABLE_COPY(QCoreApplication)
0249
0250 friend class QApplication;
0251 friend class QApplicationPrivate;
0252 friend class QGuiApplication;
0253 friend class QGuiApplicationPrivate;
0254 friend class QWidget;
0255 friend class QWidgetWindow;
0256 friend class QWidgetPrivate;
0257 friend class QWindowPrivate;
0258 #ifndef QT_NO_QOBJECT
0259 friend class QEventDispatcherUNIXPrivate;
0260 friend class QCocoaEventDispatcherPrivate;
0261 friend bool qt_sendSpontaneousEvent(QObject *, QEvent *);
0262 #endif
0263 friend Q_CORE_EXPORT QString qAppName();
0264 friend class QCommandLineParserPrivate;
0265 };
0266
0267 #define Q_DECLARE_TR_FUNCTIONS(context) \
0268 public: \
0269 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
0270 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
0271 private:
0272
0273 typedef void (*QtStartUpFunction)();
0274 typedef void (*QtCleanUpFunction)();
0275
0276 Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
0277 Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
0278 Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
0279 Q_CORE_EXPORT QString qAppName();
0280
0281 #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
0282 static void AFUNC ## _ctor_function() { \
0283 qAddPreRoutine(AFUNC); \
0284 } \
0285 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
0286
0287 #ifndef QT_NO_QOBJECT
0288 #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
0289 Q_CORE_EXPORT QString decodeMSG(const MSG &);
0290 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
0291 #endif
0292 #endif
0293
0294 QT_END_NAMESPACE
0295
0296 #include <QtCore/qcoreapplication_platform.h>
0297
0298 #endif