Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-08 08:49:13

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