Qt 4.8
qcoreapplication.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QCOREAPPLICATION_H
43 #define QCOREAPPLICATION_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtCore/qcoreevent.h>
47 #include <QtCore/qeventloop.h>
48 
49 #ifdef QT_INCLUDE_COMPAT
50 #include <QtCore/qstringlist.h>
51 #endif
52 
53 #if defined(Q_WS_WIN) && !defined(tagMSG)
54 typedef struct tagMSG MSG;
55 #endif
56 
58 
60 
61 QT_MODULE(Core)
62 
64 class QTextCodec;
65 class QTranslator;
66 class QPostEventList;
67 class QStringList;
68 
69 #define qApp QCoreApplication::instance()
70 
72 {
73  Q_OBJECT
78 
80 public:
81  enum { ApplicationFlags = QT_VERSION
82 #if !defined(QT3_SUPPORT)
83  | 0x01000000
84 #endif
85  };
86 
87 #if defined(QT_BUILD_CORE_LIB) || defined(qdoc)
88  QCoreApplication(int &argc, char **argv); // ### Qt5 remove
89 #endif
90 #if !defined(qdoc)
91  QCoreApplication(int &argc, char **argv, int
92 #if !defined(QT_BUILD_CORE_LIB)
93  = ApplicationFlags
94 #endif
95  );
96 #endif
97 
99 
100 #ifdef QT_DEPRECATED
101  QT_DEPRECATED static int argc();
102  QT_DEPRECATED static char **argv();
103 #endif
104  static QStringList arguments();
105 
106  static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
107  static bool testAttribute(Qt::ApplicationAttribute attribute);
108 
109  static void setOrganizationDomain(const QString &orgDomain);
110  static QString organizationDomain();
111  static void setOrganizationName(const QString &orgName);
112  static QString organizationName();
113  static void setApplicationName(const QString &application);
114  static QString applicationName();
115  static void setApplicationVersion(const QString &version);
116  static QString applicationVersion();
117 
118  static QCoreApplication *instance() { return self; }
119 
120  static int exec();
121  static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
122  static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
123  static void exit(int retcode=0);
124 
125  static bool sendEvent(QObject *receiver, QEvent *event);
126  static void postEvent(QObject *receiver, QEvent *event);
127  static void postEvent(QObject *receiver, QEvent *event, int priority);
128  static void sendPostedEvents(QObject *receiver, int event_type);
129  static void sendPostedEvents();
130  static void removePostedEvents(QObject *receiver);
131  static void removePostedEvents(QObject *receiver, int eventType);
132  static bool hasPendingEvents();
133 
134  virtual bool notify(QObject *, QEvent *);
135 
136  static bool startingUp();
137  static bool closingDown();
138 
139  static QString applicationDirPath();
140  static QString applicationFilePath();
141  static qint64 applicationPid();
142 
143 #ifndef QT_NO_LIBRARY
144  static void setLibraryPaths(const QStringList &);
145  static QStringList libraryPaths();
146  static void addLibraryPath(const QString &);
147  static void removeLibraryPath(const QString &);
148 #endif // QT_NO_LIBRARY
149 
150 #ifndef QT_NO_TRANSLATION
151  static void installTranslator(QTranslator * messageFile);
152  static void removeTranslator(QTranslator * messageFile);
153 #endif
154  enum Encoding { CodecForTr, UnicodeUTF8, DefaultCodec = CodecForTr };
155  // ### Qt 5: merge
156  static QString translate(const char * context,
157  const char * key,
158  const char * disambiguation = 0,
159  Encoding encoding = CodecForTr);
160  static QString translate(const char * context,
161  const char * key,
162  const char * disambiguation,
163  Encoding encoding, int n);
164 
165  static void flush();
166 
167 #if defined(QT3_SUPPORT)
168  inline QT3_SUPPORT void lock() {}
169  inline QT3_SUPPORT void unlock(bool = true) {}
170  inline QT3_SUPPORT bool locked() { return false; }
171  inline QT3_SUPPORT bool tryLock() { return false; }
172 
173  static inline QT3_SUPPORT void processOneEvent()
174  { processEvents(QEventLoop::WaitForMoreEvents); }
175  static QT3_SUPPORT int enter_loop();
176  static QT3_SUPPORT void exit_loop();
177  static QT3_SUPPORT int loopLevel();
178 #endif
179 
180 #if defined(Q_WS_WIN)
181  virtual bool winEventFilter(MSG *message, long *result);
182 #endif
183 
184 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
185  static void watchUnixSignal(int signal, bool watch);
186 #endif
187 
188  typedef bool (*EventFilter)(void *message, long *result);
189  EventFilter setEventFilter(EventFilter filter);
190  bool filterEvent(void *message, long *result);
191 
192 public Q_SLOTS:
193  static void quit();
194 
195 Q_SIGNALS:
196  void aboutToQuit();
197  void unixSignal(int);
198 
199 protected:
200  bool event(QEvent *);
201 
202  virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
203 
204 protected:
206 
207 private:
208  static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
209  bool notifyInternal(QObject *receiver, QEvent *event);
210 
211  void init();
212 
213  static QCoreApplication *self;
214 
216 
220  friend class QETWidget;
221  friend class Q3AccelManager;
223  friend class QWidget;
225  friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
226  friend Q_CORE_EXPORT QString qAppName();
228 };
229 
230 inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
231 { if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
232 
234 { if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
235 
236 inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
237 
238 #ifdef QT_NO_TRANSLATION
239 // Simple versions
240 inline QString QCoreApplication::translate(const char *, const char *sourceText,
241  const char *, Encoding encoding)
242 {
243 #ifndef QT_NO_TEXTCODEC
244  if (encoding == UnicodeUTF8)
245  return QString::fromUtf8(sourceText);
246 #else
247  Q_UNUSED(encoding)
248 #endif
249  return QString::fromLatin1(sourceText);
250 }
251 
252 // Simple versions
253 inline QString QCoreApplication::translate(const char *, const char *sourceText,
254  const char *, Encoding encoding, int)
255 {
256 #ifndef QT_NO_TEXTCODEC
257  if (encoding == UnicodeUTF8)
258  return QString::fromUtf8(sourceText);
259 #else
260  Q_UNUSED(encoding)
261 #endif
262  return QString::fromLatin1(sourceText);
263 }
264 #endif
265 
266 // ### merge the four functions into two (using "int n = -1")
267 #define Q_DECLARE_TR_FUNCTIONS(context) \
268 public: \
269  static inline QString tr(const char *sourceText, const char *disambiguation = 0) \
270  { return QCoreApplication::translate(#context, sourceText, disambiguation); } \
271  static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0) \
272  { return QCoreApplication::translate(#context, sourceText, disambiguation, \
273  QCoreApplication::UnicodeUTF8); } \
274  static inline QString tr(const char *sourceText, const char *disambiguation, int n) \
275  { return QCoreApplication::translate(#context, sourceText, disambiguation, \
276  QCoreApplication::CodecForTr, n); } \
277  static inline QString trUtf8(const char *sourceText, const char *disambiguation, int n) \
278  { return QCoreApplication::translate(#context, sourceText, disambiguation, \
279  QCoreApplication::UnicodeUTF8, n); } \
280 private:
281 
282 typedef void (*QtCleanUpFunction)();
283 
286 Q_CORE_EXPORT QString qAppName(); // get application name
287 
288 #if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
291 #endif
292 
294 
296 
297 #endif // QCOREAPPLICATION_H
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
Encoding
This enum type defines the 8-bit encoding of character string arguments to translate(): ...
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
Q_CORE_EXPORT QString decodeMSG(const MSG &)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QString organizationDomain
the Internet domain of the organization that wrote this application
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_SIGNALS
Definition: qobjectdefs.h:72
friend class QCoreApplication
Definition: qobject.h:327
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction)
static bool init
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)
QString applicationVersion
the version of this application
static void sendPostedEvents()
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
ApplicationAttribute
Definition: qnamespace.h:536
Q_CORE_EXPORT QString qAppName()
The QTranslator class provides internationalization support for text output.
Definition: qtranslator.h:59
The QCoreApplication class provides an event loop for console Qt applications.
struct tagMSG MSG
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
QString applicationName
the name of this application
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
bool notifyInternal(QObject *receiver, QEvent *event)
int key
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
Q_CORE_EXPORT QTextStream & flush(QTextStream &s)
#define QT_DEPRECATED
Definition: qglobal.h:1094
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
#define class
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void(* QtCleanUpFunction)()
QString organizationName
the name of the organization that wrote this application
#define QT_VERSION
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that spe...
Definition: qglobal.h:51