2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtCore module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 07:08:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-15 07:08:27 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QCOREAPPLICATION_H
|
|
|
|
#define QCOREAPPLICATION_H
|
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#include <QtCore/qglobal.h>
|
|
|
|
#include <QtCore/qstring.h>
|
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qobject.h>
|
|
|
|
#include <QtCore/qcoreevent.h>
|
|
|
|
#include <QtCore/qeventloop.h>
|
2012-12-06 19:02:08 +00:00
|
|
|
#else
|
|
|
|
#include <QtCore/qscopedpointer.h>
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-05-24 07:14:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(tagMSG)
|
2011-04-27 10:05:43 +00:00
|
|
|
typedef struct tagMSG MSG;
|
|
|
|
#endif
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
|
|
class QCoreApplicationPrivate;
|
|
|
|
class QTextCodec;
|
|
|
|
class QTranslator;
|
|
|
|
class QPostEventList;
|
|
|
|
class QStringList;
|
2011-09-08 15:40:55 +00:00
|
|
|
class QAbstractEventDispatcher;
|
2012-06-23 19:48:53 +00:00
|
|
|
class QAbstractNativeEventFilter;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#define qApp QCoreApplication::instance()
|
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
class Q_CORE_EXPORT QCoreApplication
|
|
|
|
#ifndef QT_NO_QOBJECT
|
|
|
|
: public QObject
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_OBJECT
|
2013-02-25 21:37:37 +00:00
|
|
|
Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged)
|
|
|
|
Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged)
|
|
|
|
Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged)
|
|
|
|
Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged)
|
2011-10-26 11:29:51 +00:00
|
|
|
Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Q_DECLARE_PRIVATE(QCoreApplication)
|
|
|
|
public:
|
|
|
|
enum { ApplicationFlags = QT_VERSION
|
|
|
|
};
|
|
|
|
|
2012-10-16 10:55:49 +00:00
|
|
|
QCoreApplication(int &argc, char **argv
|
|
|
|
#ifndef Q_QDOC
|
|
|
|
, int = ApplicationFlags
|
|
|
|
#endif
|
|
|
|
);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
~QCoreApplication();
|
|
|
|
|
|
|
|
static QStringList arguments();
|
|
|
|
|
|
|
|
static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
|
|
|
|
static bool testAttribute(Qt::ApplicationAttribute attribute);
|
|
|
|
|
|
|
|
static void setOrganizationDomain(const QString &orgDomain);
|
|
|
|
static QString organizationDomain();
|
|
|
|
static void setOrganizationName(const QString &orgName);
|
|
|
|
static QString organizationName();
|
|
|
|
static void setApplicationName(const QString &application);
|
|
|
|
static QString applicationName();
|
|
|
|
static void setApplicationVersion(const QString &version);
|
|
|
|
static QString applicationVersion();
|
|
|
|
|
2014-01-01 16:58:19 +00:00
|
|
|
static void setSetuidAllowed(bool allow);
|
|
|
|
static bool isSetuidAllowed();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
static QCoreApplication *instance() { return self; }
|
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
static int exec();
|
|
|
|
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
|
|
|
|
static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
|
|
|
|
static void exit(int retcode=0);
|
|
|
|
|
|
|
|
static bool sendEvent(QObject *receiver, QEvent *event);
|
2012-02-19 09:15:18 +00:00
|
|
|
static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
|
2017-09-18 09:49:52 +00:00
|
|
|
static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
|
2012-02-19 09:15:18 +00:00
|
|
|
static void removePostedEvents(QObject *receiver, int eventType = 0);
|
Deprecate {QCoreApp,QAbstractEventDispatcher}::hasPendingEvents()
This function has a flawed design. It was flawed when it was added in
Qt 3.0.
A "false" return value is racy: any other thread running may post events
to the current thread, thus making the result stale. That includes Qt
starts for its own purposes when it comes to the main thread, like the
Scene Graph thread, the QProcessManager thread, the Windows
QAdoptedThread watcher thread, the Windows pipe writer thread, etc.
A "true" return is stable only if the selected thread is stopped, which
includes selecting the current thread (the case of QCoreApplication).
For that reason, this method should not be public, but a protected one
so that a public static could call it. But even that would not solve the
race condition from the previous paragraph (hence why
QCoreApplication::hasPendingEvents being deprecated too).
And, to top all of that off, all but one of the implementations access
the GUI thread's event loop counter in a non-thread-safe manner. I've
changed the documentation to restrict to the only currently-working use-
application.
[ChangeLog][QtCore][Event loop] QCoreApplication::hasPendingEvents and
QAbstractEventDispatcher::hasPendingEvents are now deprecated. Please
refer to the documentation for more information.
Task-number: QTBUG-36611
Change-Id: Iac61f307e9672839944ae2f75abb1aea30c419f6
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2014-02-03 23:37:42 +00:00
|
|
|
#if QT_DEPRECATED_SINCE(5, 3)
|
|
|
|
QT_DEPRECATED static bool hasPendingEvents();
|
|
|
|
#endif
|
2011-09-08 15:40:55 +00:00
|
|
|
static QAbstractEventDispatcher *eventDispatcher();
|
|
|
|
static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
virtual bool notify(QObject *, QEvent *);
|
|
|
|
|
|
|
|
static bool startingUp();
|
|
|
|
static bool closingDown();
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
static QString applicationDirPath();
|
|
|
|
static QString applicationFilePath();
|
2017-09-30 17:00:32 +00:00
|
|
|
static qint64 applicationPid() Q_DECL_CONST_FUNCTION;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-12-19 09:34:32 +00:00
|
|
|
#if QT_CONFIG(library)
|
2011-04-27 10:05:43 +00:00
|
|
|
static void setLibraryPaths(const QStringList &);
|
|
|
|
static QStringList libraryPaths();
|
|
|
|
static void addLibraryPath(const QString &);
|
|
|
|
static void removeLibraryPath(const QString &);
|
2016-12-19 09:34:32 +00:00
|
|
|
#endif // QT_CONFIG(library)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_TRANSLATION
|
2012-03-20 07:47:57 +00:00
|
|
|
static bool installTranslator(QTranslator * messageFile);
|
|
|
|
static bool removeTranslator(QTranslator * messageFile);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2012-05-16 21:09:56 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
static QString translate(const char * context,
|
|
|
|
const char * key,
|
2017-09-18 09:49:52 +00:00
|
|
|
const char * disambiguation = nullptr,
|
2011-11-28 14:24:25 +00:00
|
|
|
int n = -1);
|
2012-05-16 21:09:56 +00:00
|
|
|
#if QT_DEPRECATED_SINCE(5, 0)
|
|
|
|
enum Encoding { UnicodeUTF8, Latin1, DefaultCodec = UnicodeUTF8, CodecForTr = UnicodeUTF8 };
|
|
|
|
QT_DEPRECATED static inline QString translate(const char * context, const char * key,
|
|
|
|
const char * disambiguation, Encoding, int n = -1)
|
|
|
|
{ return translate(context, key, disambiguation, n); }
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2017-04-20 14:07:06 +00:00
|
|
|
# if QT_DEPRECATED_SINCE(5, 9)
|
|
|
|
QT_DEPRECATED static void flush();
|
|
|
|
# endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-06-23 19:48:53 +00:00
|
|
|
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
|
|
|
|
void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-26 11:29:51 +00:00
|
|
|
static bool isQuitLockEnabled();
|
|
|
|
static void setQuitLockEnabled(bool enabled);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
static void quit();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2015-04-17 08:29:04 +00:00
|
|
|
void aboutToQuit(QPrivateSignal);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-02-25 21:37:37 +00:00
|
|
|
void organizationNameChanged();
|
|
|
|
void organizationDomainChanged();
|
|
|
|
void applicationNameChanged();
|
|
|
|
void applicationVersionChanged();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
protected:
|
2017-09-18 08:36:49 +00:00
|
|
|
bool event(QEvent *) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif // QT_NO_QOBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QCoreApplication(QCoreApplicationPrivate &p);
|
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifdef QT_NO_QOBJECT
|
|
|
|
QScopedPointer<QCoreApplicationPrivate> d_ptr;
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
private:
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
|
2015-04-16 22:44:16 +00:00
|
|
|
# if QT_DEPRECATED_SINCE(5,6)
|
|
|
|
QT_DEPRECATED bool notifyInternal(QObject *receiver, QEvent *event); // ### Qt6 BIC: remove me
|
|
|
|
# endif
|
|
|
|
static bool notifyInternal2(QObject *receiver, QEvent *);
|
2017-05-16 16:46:50 +00:00
|
|
|
static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
static QCoreApplication *self;
|
2011-10-26 11:29:51 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_DISABLE_COPY(QCoreApplication)
|
|
|
|
|
|
|
|
friend class QApplication;
|
|
|
|
friend class QApplicationPrivate;
|
2011-04-27 12:56:55 +00:00
|
|
|
friend class QGuiApplication;
|
|
|
|
friend class QGuiApplicationPrivate;
|
2011-04-27 10:05:43 +00:00
|
|
|
friend class QWidget;
|
2011-05-02 07:25:17 +00:00
|
|
|
friend class QWidgetWindow;
|
2011-04-27 10:05:43 +00:00
|
|
|
friend class QWidgetPrivate;
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
|
|
|
friend class QEventDispatcherUNIXPrivate;
|
2011-06-21 11:40:57 +00:00
|
|
|
friend class QCocoaEventDispatcherPrivate;
|
2011-04-27 10:05:43 +00:00
|
|
|
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
friend Q_CORE_EXPORT QString qAppName();
|
|
|
|
friend class QClassFactory;
|
|
|
|
};
|
|
|
|
|
2012-12-06 20:05:34 +00:00
|
|
|
#ifdef QT_NO_DEPRECATED
|
|
|
|
# define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context)
|
|
|
|
#else
|
|
|
|
# define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
|
2017-09-18 09:49:52 +00:00
|
|
|
QT_DEPRECATED static inline QString trUtf8(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
|
2012-12-06 20:05:34 +00:00
|
|
|
{ return QCoreApplication::translate(#context, sourceText, disambiguation, n); }
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#define Q_DECLARE_TR_FUNCTIONS(context) \
|
|
|
|
public: \
|
2017-09-18 09:49:52 +00:00
|
|
|
static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
|
2012-05-16 21:09:56 +00:00
|
|
|
{ return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
|
2012-12-06 20:05:34 +00:00
|
|
|
QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
|
2011-04-27 10:05:43 +00:00
|
|
|
private:
|
|
|
|
|
2013-01-14 11:58:31 +00:00
|
|
|
typedef void (*QtStartUpFunction)();
|
2011-04-27 10:05:43 +00:00
|
|
|
typedef void (*QtCleanUpFunction)();
|
|
|
|
|
2013-01-14 11:58:31 +00:00
|
|
|
Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
|
|
|
|
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
|
|
|
|
Q_CORE_EXPORT QString qAppName(); // get application name
|
|
|
|
|
2013-01-14 11:58:31 +00:00
|
|
|
#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
|
|
|
|
static void AFUNC ## _ctor_function() { \
|
|
|
|
qAddPreRoutine(AFUNC); \
|
|
|
|
} \
|
|
|
|
Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
|
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
2011-05-24 07:14:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_CORE_EXPORT QString decodeMSG(const MSG &);
|
|
|
|
Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
|
|
|
|
#endif
|
2012-12-06 19:02:08 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // QCOREAPPLICATION_H
|