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