File indexing completed on 2026-09-05 09:19:01
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 static QCoreApplication *instance() noexcept { return self; }
0099 static bool instanceExists() noexcept;
0100 #endif
0101
0102 #ifndef QT_NO_QOBJECT
0103 static int exec();
0104 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
0105 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
0106 static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline);
0107
0108 static bool sendEvent(QObject *receiver, QEvent *event);
0109 static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
0110 static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
0111 static void removePostedEvents(QObject *receiver, int eventType = 0);
0112 static QAbstractEventDispatcher *eventDispatcher();
0113 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
0114
0115 virtual bool notify(QObject *, QEvent *);
0116
0117 static bool startingUp();
0118 static bool closingDown();
0119 #endif
0120
0121 static QString applicationDirPath();
0122 static QString applicationFilePath();
0123 Q_DECL_CONST_FUNCTION static qint64 applicationPid() noexcept;
0124
0125 #if QT_CONFIG(permissions) || defined(Q_QDOC)
0126 Qt::PermissionStatus checkPermission(const QPermission &permission);
0127
0128 # ifdef Q_QDOC
0129 template <typename Functor>
0130 void requestPermission(const QPermission &permission, const QObject *context, Functor functor);
0131 # else
0132
0133
0134 template <typename Functor,
0135 std::enable_if_t<
0136 QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value,
0137 bool> = true>
0138 void requestPermission(const QPermission &permission,
0139 const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver,
0140 Functor &&func)
0141 {
0142 requestPermissionImpl(permission,
0143 QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)),
0144 receiver);
0145 }
0146 # endif
0147
0148 #ifndef QT_NO_CONTEXTLESS_CONNECT
0149 #ifdef Q_QDOC
0150 template <typename Functor>
0151 #else
0152
0153 template <typename Functor,
0154 std::enable_if_t<
0155 QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value,
0156 bool> = true>
0157 #endif
0158 void requestPermission(const QPermission &permission, Functor &&func)
0159 {
0160 requestPermission(permission, nullptr, std::forward<Functor>(func));
0161 }
0162 #endif
0163
0164 #if QT_CORE_REMOVED_SINCE(6, 10)
0165 private:
0166 void requestPermission(const QPermission &permission,
0167 QtPrivate::QSlotObjectBase *slotObj, const QObject *context);
0168 public:
0169 #endif
0170
0171 #endif
0172
0173 #if QT_CONFIG(library)
0174 static void setLibraryPaths(const QStringList &);
0175 static QStringList libraryPaths();
0176 static void addLibraryPath(const QString &);
0177 static void removeLibraryPath(const QString &);
0178 #endif
0179
0180 #ifndef QT_NO_TRANSLATION
0181 static bool installTranslator(QTranslator * messageFile);
0182 static bool removeTranslator(QTranslator * messageFile);
0183 #endif
0184
0185 static QString translate(const char * context,
0186 const char * key,
0187 const char * disambiguation = nullptr,
0188 int n = -1);
0189
0190 QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QCoreApplication)
0191
0192 #ifndef QT_NO_QOBJECT
0193 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
0194 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
0195
0196 static bool isQuitLockEnabled();
0197 static void setQuitLockEnabled(bool enabled);
0198
0199 public Q_SLOTS:
0200 static void quit();
0201 static void exit(int retcode = 0);
0202
0203 Q_SIGNALS:
0204 void aboutToQuit(QPrivateSignal);
0205
0206 void organizationNameChanged();
0207 void organizationDomainChanged();
0208 void applicationNameChanged();
0209 void applicationVersionChanged();
0210
0211 protected:
0212 bool event(QEvent *) override;
0213
0214 # if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0215 QT_DEPRECATED_VERSION_X_6_10("This feature will be removed in Qt 7")
0216 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
0217 # endif
0218 #endif
0219
0220 protected:
0221 QCoreApplication(QCoreApplicationPrivate &p);
0222
0223 #ifdef QT_NO_QOBJECT
0224 std::unique_ptr<QCoreApplicationPrivate> d_ptr;
0225 #endif
0226
0227 private:
0228 #ifndef QT_NO_QOBJECT
0229 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
0230 static bool notifyInternal2(QObject *receiver, QEvent *);
0231 static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
0232
0233 void requestPermissionImpl(const QPermission &permission, QtPrivate::QSlotObjectBase *slotObj,
0234 const QObject *context);
0235 #endif
0236
0237 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0238 static QBasicAtomicPointer<QCoreApplication> self;
0239 #else
0240 static QCoreApplication *self;
0241 #endif
0242
0243 Q_DISABLE_COPY(QCoreApplication)
0244
0245 friend class QApplication;
0246 friend class QApplicationPrivate;
0247 friend class QGuiApplication;
0248 friend class QGuiApplicationPrivate;
0249 friend class QWidget;
0250 friend class QWidgetWindow;
0251 friend class QWidgetPrivate;
0252 friend class QWindowPrivate;
0253 #ifndef QT_NO_QOBJECT
0254 friend class QEventDispatcherUNIXPrivate;
0255 friend class QCocoaEventDispatcherPrivate;
0256 friend bool qt_sendSpontaneousEvent(QObject *, QEvent *);
0257 #endif
0258 friend Q_CORE_EXPORT QString qAppName();
0259 friend class QCommandLineParserPrivate;
0260 };
0261
0262 #define Q_DECLARE_TR_FUNCTIONS(context) \
0263 public: \
0264 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
0265 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
0266 private:
0267
0268 typedef void (*QtStartUpFunction)();
0269 typedef void (*QtCleanUpFunction)();
0270
0271 Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
0272 Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
0273 Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
0274 Q_CORE_EXPORT QString qAppName();
0275
0276 #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
0277 static void AFUNC ## _ctor_function() { \
0278 qAddPreRoutine(AFUNC); \
0279 } \
0280 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
0281
0282 #ifndef QT_NO_QOBJECT
0283 #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
0284 Q_CORE_EXPORT QString decodeMSG(const MSG &);
0285 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
0286 #endif
0287 #endif
0288
0289 QT_END_NAMESPACE
0290
0291 #include <QtCore/qcoreapplication_platform.h>
0292
0293 #endif