2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2020-07-16 16:00:15 +00:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2016-01-15 07:08:27 +00:00
|
|
|
** 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 QTranslator;
|
|
|
|
class QPostEventList;
|
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);
|
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);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-12-06 19:02:08 +00:00
|
|
|
#ifndef QT_NO_QOBJECT
|
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
|
|
|
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
|
QCoreApplication: work towards replacing a QRecursiveMutex with a QMutex
At first glance, libraryPathMutex is only recursive because
setLibraryPaths(), addLibraryPath() and removeLibraryPath(), all of
which lock libraryPathMutex, may call libraryPaths(), which does, too.
This is easily fixed by splitting libraryPaths() into public
libraryPaths() and private libraryPathsLocked(), the latter expecting
to be called with the libraryPathMutex already held. And this is what
this patch does.
However, on second glance, the building of the initial app_libpaths
calls a monstrous amount of code, incl. QLibraryInfo, and some of
that code probably re-enters one of the library-path functions.
So while this patch is a step towards making libraryPathMutex
non-recursive, it's probably not the end.
Change-Id: I3ed83272ace6966980cf8e1db877f24c89789da3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2019-08-21 20:14:16 +00:00
|
|
|
#if QT_CONFIG(library)
|
|
|
|
static QStringList libraryPathsLocked();
|
|
|
|
#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;
|
2019-05-15 13:28:18 +00:00
|
|
|
friend class QCommandLineParserPrivate;
|
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); } \
|
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
|