- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qcoreapplication.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QCOREAPPLICATION_H
    00043 #define QCOREAPPLICATION_H
    00044
    00045 #include <QtCore/qobject.h>
    00046 #include <QtCore/qcoreevent.h>
    00047 #include <QtCore/qeventloop.h>
    00048
    00049 #ifdef QT_INCLUDE_COMPAT
    00050 #include <QtCore/qstringlist.h>
    00051 #endif
    00052
    00053 #if defined(Q_WS_WIN) && !defined(tagMSG)
    00054 typedef struct tagMSG MSG;
    00055 #endif
    00056
    00057 QT_BEGIN_HEADER
    00058
    00059 QT_BEGIN_NAMESPACE
    00060
    00061 QT_MODULE(Core)
    00062
    00063 class QCoreApplicationPrivate;
    00064 class QTextCodec;
    00065 class QTranslator;
    00066 class QPostEventList;
    00067 class QStringList;
    00068
    00069 #define qApp QCoreApplication::instance()
    00070
    00071 class Q_CORE_EXPORT QCoreApplication : public QObject
    00072 {
    00073     Q_OBJECT
    00074     Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
    00075     Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion)
    00076     Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
    00077     Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
    00078
    00079     Q_DECLARE_PRIVATE(QCoreApplication)
    00080 public:
    00081     QCoreApplication(int &argc, char **argv);
    00082     ~QCoreApplication();
    00083
    00084 #ifdef QT_DEPRECATED
    00085     QT_DEPRECATED static int argc();
    00086     QT_DEPRECATED static char **argv();
    00087 #endif
    00088     static QStringList arguments();
    00089
    00090     static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
    00091     static bool testAttribute(Qt::ApplicationAttribute attribute);
    00092
    00093     static void setOrganizationDomain(const QString &orgDomain);
    00094     static QString organizationDomain();
    00095     static void setOrganizationName(const QString &orgName);
    00096     static QString organizationName();
    00097     static void setApplicationName(const QString &application);
    00098     static QString applicationName();
    00099     static void setApplicationVersion(const QString &version);
    00100     static QString applicationVersion();
    00101
    00102     static QCoreApplication *instance() { return self; }
    00103
    00104     static int exec();
    00105     static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
    00106     static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
    00107     static void exit(int retcode=0);
    00108
    00109     static bool sendEvent(QObject *receiver, QEvent *event);
    00110     static void postEvent(QObject *receiver, QEvent *event);
    00111     static void postEvent(QObject *receiver, QEvent *event, int priority);
    00112     static void sendPostedEvents(QObject *receiver, int event_type);
    00113     static void sendPostedEvents();
    00114     static void removePostedEvents(QObject *receiver);
    00115     static void removePostedEvents(QObject *receiver, int eventType);
    00116     static bool hasPendingEvents();
    00117
    00118     virtual bool notify(QObject *, QEvent *);
    00119
    00120     static bool startingUp();
    00121     static bool closingDown();
    00122
    00123     static QString applicationDirPath();
    00124     static QString applicationFilePath();
    00125     static qint64 applicationPid();
    00126
    00127 #ifndef QT_NO_LIBRARY
    00128     static void setLibraryPaths(const QStringList &);
    00129     static QStringList libraryPaths();
    00130     static void addLibraryPath(const QString &);
    00131     static void removeLibraryPath(const QString &);
    00132 #endif // QT_NO_LIBRARY
    00133
    00134 #ifndef QT_NO_TRANSLATION
    00135     static void installTranslator(QTranslator * messageFile);
    00136     static void removeTranslator(QTranslator * messageFile);
    00137 #endif
    00138     enum Encoding { CodecForTr, UnicodeUTF8, DefaultCodec = CodecForTr };
    00139     // ### Qt 5: merge
    00140     static QString translate(const char * context,
    00141                              const char * key,
    00142                              const char * disambiguation = 0,
    00143                              Encoding encoding = CodecForTr);
    00144     static QString translate(const char * context,
    00145                              const char * key,
    00146                              const char * disambiguation,
    00147                              Encoding encoding, int n);
    00148
    00149     static void flush();
    00150
    00151 #if defined(QT3_SUPPORT)
    00152     inline QT3_SUPPORT void lock() {}
    00153     inline QT3_SUPPORT void unlock(bool = true) {}
    00154     inline QT3_SUPPORT bool locked() { return false; }
    00155     inline QT3_SUPPORT bool tryLock() { return false; }
    00156
    00157     static inline QT3_SUPPORT void processOneEvent()
    00158     { processEvents(QEventLoop::WaitForMoreEvents); }
    00159     static QT3_SUPPORT int enter_loop();
    00160     static QT3_SUPPORT void exit_loop();
    00161     static QT3_SUPPORT int loopLevel();
    00162 #endif
    00163
    00164 #if defined(Q_WS_WIN)
    00165     virtual bool winEventFilter(MSG *message, long *result);
    00166 #endif
    00167
    00168 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
    00169     static void watchUnixSignal(int signal, bool watch);
    00170 #endif
    00171
    00172     typedef bool (*EventFilter)(void *message, long *result);
    00173     EventFilter setEventFilter(EventFilter filter);
    00174     bool filterEvent(void *message, long *result);
    00175
    00176 public Q_SLOTS:
    00177     static void quit();
    00178
    00179 Q_SIGNALS:
    00180     void aboutToQuit();
    00181     void unixSignal(int);
    00182
    00183 protected:
    00184     bool event(QEvent *);
    00185
    00186     virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
    00187
    00188 protected:
    00189     QCoreApplication(QCoreApplicationPrivate &p);
    00190
    00191 private:
    00192     static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
    00193     bool notifyInternal(QObject *receiver, QEvent *event);
    00194
    00195     void init();
    00196
    00197     static QCoreApplication *self;
    00198
    00199     Q_DISABLE_COPY(QCoreApplication)
    00200
    00201     friend class QEventDispatcherUNIXPrivate;
    00202     friend class QApplication;
    00203     friend class QApplicationPrivate;
    00204     friend class QETWidget;
    00205     friend class Q3AccelManager;
    00206     friend class QShortcutMap;
    00207     friend class QWidget;
    00208     friend class QWidgetPrivate;
    00209     friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
    00210     friend Q_CORE_EXPORT QString qAppName();
    00211     friend class QClassFactory;
    00212 };
    00213
    00214 inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
    00215 {  if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
    00216
    00217 inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
    00218 { if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
    00219
    00220 inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
    00221
    00222 #ifdef QT_NO_TRANSLATION
    00223 // Simple versions
    00224 inline QString QCoreApplication::translate(const char *, const char *sourceText,
    00225                                            const char *, Encoding encoding)
    00226 {
    00227 #ifndef QT_NO_TEXTCODEC
    00228     if (encoding == UnicodeUTF8)
    00229         return QString::fromUtf8(sourceText);
    00230 #else
    00231     Q_UNUSED(encoding)
    00232 #endif
    00233     return QString::fromLatin1(sourceText);
    00234 }
    00235
    00236 // Simple versions
    00237 inline QString QCoreApplication::translate(const char *, const char *sourceText,
    00238                                            const char *, Encoding encoding, int)
    00239 {
    00240 #ifndef QT_NO_TEXTCODEC
    00241     if (encoding == UnicodeUTF8)
    00242         return QString::fromUtf8(sourceText);
    00243 #else
    00244     Q_UNUSED(encoding)
    00245 #endif
    00246     return QString::fromLatin1(sourceText);
    00247 }
    00248 #endif
    00249
    00250 // ### merge the four functions into two (using "int n = -1")
    00251 #define Q_DECLARE_TR_FUNCTIONS(context) \
    00252 public: \
    00253     static inline QString tr(const char *sourceText, const char *disambiguation = 0) \
    00254         { return QCoreApplication::translate(#context, sourceText, disambiguation); } \
    00255     static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0) \
    00256         { return QCoreApplication::translate(#context, sourceText, disambiguation, \
    00257                                              QCoreApplication::UnicodeUTF8); } \
    00258     static inline QString tr(const char *sourceText, const char *disambiguation, int n) \
    00259         { return QCoreApplication::translate(#context, sourceText, disambiguation, \
    00260                                              QCoreApplication::CodecForTr, n); } \
    00261     static inline QString trUtf8(const char *sourceText, const char *disambiguation, int n) \
    00262         { return QCoreApplication::translate(#context, sourceText, disambiguation, \
    00263                                              QCoreApplication::UnicodeUTF8, n); } \
    00264 private:
    00265
    00266 typedef void (*QtCleanUpFunction)();
    00267
    00268 Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
    00269 Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
    00270 Q_CORE_EXPORT QString qAppName();                // get application name
    00271
    00272 #if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
    00273 Q_CORE_EXPORT QString decodeMSG(const MSG &);
    00274 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
    00275 #endif
    00276
    00277 QT_END_NAMESPACE
    00278
    00279 QT_END_HEADER
    00280
    00281 #endif // QCOREAPPLICATION_H