Qt 4.8
qcoreapplication.cpp
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 #include "qcoreapplication.h"
43 #include "qcoreapplication_p.h"
44 
46 #include "qcoreevent.h"
47 #include "qeventloop.h"
48 #include "qcorecmdlineargs_p.h"
49 #include <qdatastream.h>
50 #include <qdebug.h>
51 #include <qdir.h>
52 #include <qfile.h>
53 #include <qfileinfo.h>
54 #include <qhash.h>
55 #include <private/qprocess_p.h>
56 #include <qtextcodec.h>
57 #include <qthread.h>
58 #include <qthreadpool.h>
59 #include <qthreadstorage.h>
60 #include <private/qthread_p.h>
61 #include <qelapsedtimer.h>
62 #include <qlibraryinfo.h>
63 #include <qvarlengtharray.h>
64 #include <private/qfactoryloader_p.h>
65 #include <private/qfunctions_p.h>
66 #include <private/qlocale_p.h>
67 #include <private/qmutexpool_p.h>
68 
69 #ifdef Q_OS_SYMBIAN
70 # include <exception>
71 # include <f32file.h>
72 # include <e32ldr.h>
73 # include "qeventdispatcher_symbian_p.h"
74 # include "private/qcore_symbian_p.h"
75 # include "private/qfilesystemengine_p.h"
76 # include <apacmdln.h>
77 #elif defined(Q_OS_UNIX)
78 # if defined(Q_OS_BLACKBERRY)
80 # include <process.h>
81 # include <unistd.h>
82 # else
83 # if !defined(QT_NO_GLIB)
84 # include "qeventdispatcher_glib_p.h"
85 # endif
86 # include "qeventdispatcher_unix_p.h"
87 # endif
88 #endif
89 
90 #ifdef Q_OS_WIN
91 # include "qeventdispatcher_win_p.h"
92 #endif
93 
94 #ifdef Q_OS_MAC
95 # include "qcore_mac_p.h"
96 #endif
97 
98 #include <stdlib.h>
99 
100 #ifdef Q_OS_UNIX
101 # include <locale.h>
102 #endif
103 
104 #ifdef Q_OS_VXWORKS
105 # include <taskLib.h>
106 #endif
107 
108 #ifdef Q_OS_QNX
109 # include <sys/neutrino.h>
110 # include <pthread.h>
111 # include <sched.h>
112 #endif
113 
115 
117 {
118 public:
119  inline explicit QMutexUnlocker(QMutex *m)
120  : mtx(m)
121  { }
122  inline ~QMutexUnlocker() { unlock(); }
123  inline void unlock() { if (mtx) mtx->unlock(); mtx = 0; }
124 
125 private:
127 
129 };
130 
131 #ifdef Q_OS_SYMBIAN
132 static CApaCommandLine* apaCommandLine = 0;
133 static char *apaTail = 0;
134 static QVector<char *> *apaArgv = 0;
135 
136 static void qt_cleanup_apa_cmd_line()
137 {
138  delete apaCommandLine;
139  apaCommandLine = 0;
140  delete apaArgv;
141  apaArgv = 0;
142  delete apaTail;
143  apaTail = 0;
144 }
145 
146 static inline void qt_init_symbian_apa_arguments(int &argc, char **&argv)
147 {
148  // If app is launched via CApaCommandLine::StartApp(), normal arguments only contain
149  // application name.
150  if (argc == 1) {
151  CApaCommandLine* commandLine = QCoreApplicationPrivate::symbianCommandLine();
152  if(commandLine) {
153  TPtrC8 apaCmdLine = commandLine->TailEnd();
154  int tailLen = apaCmdLine.Length();
155  if (tailLen) {
156  apaTail = reinterpret_cast<char *>(qMalloc(tailLen + 1));
157  qMemCopy(apaTail, reinterpret_cast<const char *>(apaCmdLine.Ptr()), tailLen);
158  apaTail[tailLen] = '\0';
159  apaArgv = new QVector<char *>(8);
160  // Reuse windows command line parsing
161  *apaArgv = qWinCmdLine<char>(apaTail, tailLen, argc);
162  apaArgv->insert(0, argv[0]);
163  argc++;
164  argv = apaArgv->data();
165  }
166  }
167  }
168 }
169 
170 CApaCommandLine* QCoreApplicationPrivate::symbianCommandLine()
171 {
172  // Getting of Apa command line needs to be static as it can only be called successfully
173  // once per process.
174  if (!apaCommandLine) {
175  TInt err = CApaCommandLine::GetCommandLineFromProcessEnvironment(apaCommandLine);
176  if (err == KErrNone) {
177  qAddPostRoutine(qt_cleanup_apa_cmd_line);
178  }
179  }
180  return apaCommandLine;
181 }
182 
183 #endif
184 
185 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
186 extern QString qAppFileName();
187 #endif
188 
189 int QCoreApplicationPrivate::app_compile_version = 0x040000; //we don't know exactly, but it's at least 4.0.0
190 #if defined(QT3_SUPPORT)
191 bool QCoreApplicationPrivate::useQt3Support = true;
192 #endif
193 
194 #if !defined(Q_OS_WIN)
195 #ifdef Q_OS_MAC
197 {
198  QString bundleName;
199  CFTypeRef string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("CFBundleName"));
200  if (string)
201  bundleName = QCFString::toQString(static_cast<CFStringRef>(string));
202  return bundleName;
203 }
204 #endif
206 {
207  QMutexLocker locker(QMutexPool::globalInstanceGet(&applicationName));
208 
209  if (applicationName.isNull()) {
210 #ifdef Q_OS_MAC
211  applicationName = macMenuBarName();
212 #endif
213  if (applicationName.isEmpty() && argv[0]) {
214  char *p = strrchr(argv[0], '/');
215  applicationName = QString::fromLocal8Bit(p ? p + 1 : argv[0]);
216  }
217  }
218  return applicationName;
219 }
220 #endif
221 
222 bool QCoreApplicationPrivate::checkInstance(const char *function)
223 {
224  bool b = (QCoreApplication::self != 0);
225  if (!b)
226  qWarning("QApplication::%s: Please instantiate the QApplication object first", function);
227  return b;
228 }
229 
230 Q_GLOBAL_STATIC(QString, qmljs_debug_arguments);
231 
233 {
234  int j = argc ? 1 : 0;
235  for (int i = 1; i < argc; ++i) {
236  if (argv[i] && *argv[i] != '-') {
237  argv[j++] = argv[i];
238  continue;
239  }
240  QByteArray arg = argv[i];
241  if (arg.startsWith("-qmljsdebugger=")) {
242  *qmljs_debug_arguments() = QString::fromLocal8Bit(arg.right(arg.length() - 15));
243  } else if (arg == "-qmljsdebugger" && i < argc - 1) {
244  ++i;
245  *qmljs_debug_arguments() = QString::fromLocal8Bit(argv[i]);
246  } else {
247  argv[j++] = argv[i];
248  }
249  }
250 
251  if (j < argc) {
252  argv[j] = 0;
253  argc = j;
254  }
255 }
256 
257 // Support for introspection
258 
260 
262 {
263  qt_signal_spy_callback_set = callback_set;
264 }
265 
267 {
268 }
269 
271 Q_GLOBAL_STATIC(QVFuncList, postRList)
272 
274 {
275  QVFuncList *list = postRList();
276  if (!list)
277  return;
278  list->prepend(p);
279 }
280 
282 {
283  QVFuncList *list = postRList();
284  if (!list)
285  return;
286  list->removeAll(p);
287 }
288 
290 {
291  QVFuncList *list = 0;
292  QT_TRY {
293  list = postRList();
294  } QT_CATCH(const std::bad_alloc &) {
295  // ignore - if we can't allocate a post routine list,
296  // there's a high probability that there's no post
297  // routine to be executed :)
298  }
299  if (!list)
300  return;
301  while (!list->isEmpty())
302  (list->takeFirst())();
303 }
304 
305 
306 // app starting up if false
308  // app closing down if true
310 // initialized in qcoreapplication and in qtextstream autotest when setlocale is called.
312 
313 #ifdef Q_OS_SYMBIAN
314 // The global QSettings needs to be cleaned where cleanup stack is available, which is not
315 // normally the case when global static destructors are run.
316 // Declare a custom QGlobalStaticDeleter for QSettings to handle that case.
317 template<>
319 {
320 public:
321  QGlobalStatic<QSettings> &globalStatic;
323  : globalStatic(_globalStatic)
324  { }
325 
326  inline ~QGlobalStaticDeleter()
327  {
328  CTrapCleanup *cleanup = CTrapCleanup::New();
329  delete globalStatic.pointer;
330  delete cleanup;
331  globalStatic.pointer = 0;
332  globalStatic.destroyed = true;
333  }
334 };
335 #endif
336 
337 /*
338  Create an instance of Trolltech.conf. This ensures that the settings will not
339  be thrown out of QSetting's cache for unused settings.
340  */
342 
343 QSettings *QCoreApplicationPrivate::trolltechConf()
344 {
345  return staticTrolltechConf();
346 }
347 
349 {
350  QThreadData *currentThreadData = QThreadData::current();
351  return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset;
352 }
353 
354 
356 {
358 }
359 
360 
361 
365 
366 #ifdef Q_OS_UNIX
368 #endif
369 
372 #ifndef QT_NO_LIBRARY
373  app_libpaths = 0;
374 #endif
375  }
377 #ifndef QT_NO_LIBRARY
378  delete app_libpaths;
379 #endif
380 #ifndef QT_NO_QOBJECT
381  // cleanup the QAdoptedThread created for the main() thread
384  data->deref(); // deletes the data and the adopted thread
385  }
386 #endif
387  }
388 
389 #ifdef Q_OS_BLACKBERRY
390  //The QCoreApplicationData struct is only populated on demand, because it is rarely needed and would
391  //affect startup time
392  void loadManifest() {
393  static bool manifestLoadAttempt = false;
394  if (manifestLoadAttempt)
395  return;
396 
397  manifestLoadAttempt = true;
398 
399  QFile metafile(QLatin1String("app/META-INF/MANIFEST.MF"));
400  if (!metafile.open(QIODevice::ReadOnly)) {
401  qWarning() << Q_FUNC_INFO << "Could not open application metafile for reading";
402  } else {
403  while (!metafile.atEnd() && (application.isEmpty() || applicationVersion.isEmpty() || orgName.isEmpty())) {
404  QByteArray line = metafile.readLine();
405  if (line.startsWith("Application-Name:"))
406  application = QString::fromUtf8(line.mid(18).trimmed());
407  else if (line.startsWith("Application-Version:"))
408  applicationVersion = QString::fromUtf8(line.mid(21).trimmed());
409  else if (line.startsWith("Package-Author:"))
410  orgName = QString::fromUtf8(line.mid(16).trimmed());
411  }
412  metafile.close();
413  }
414  }
415 #endif
416 
417  QString orgName, orgDomain, application;
419 
420 #ifndef QT_NO_LIBRARY
422 #endif
423 
424 };
425 
427 
429  : QObjectPrivate(), argc(aargc), argv(aargv), application_type(0), eventFilter(0),
430  in_exec(false), aboutToQuitEmitted(false)
431 {
432  app_compile_version = flags & 0xffffff;
433 #if defined(QT3_SUPPORT)
434  useQt3Support = !(flags & 0x01000000);
435 #endif
436  static const char *const empty = "";
437  if (argc == 0 || argv == 0) {
438  argc = 0;
439  argv = (char **)&empty; // ouch! careful with QCoreApplication::argv()!
440  }
441  QCoreApplicationPrivate::is_app_closing = false;
442 
443 #ifdef Q_OS_SYMBIAN
444  qt_init_symbian_apa_arguments(argc, argv);
445 #endif
446 
447 #ifdef Q_OS_UNIX
448  qt_application_thread_id = QThread::currentThreadId();
449 #endif
450 
451 #ifdef Q_OS_QNX
452  // make the kernel attempt to emulate an instruction with a misaligned access
453  // if the attempt fails, it faults with a SIGBUS
454  int tv = -1;
455  ThreadCtl(_NTO_TCTL_ALIGN_FAULT, &tv);
456 
457  // without Round Robin drawn intensive apps will hog the cpu
458  // and make the system appear frozen
459  int sched_policy;
460  sched_param param;
461  if (pthread_getschedparam(0, &sched_policy, &param) == 0 && sched_policy != SCHED_RR) {
462  sched_policy = SCHED_RR;
463  pthread_setschedparam(0, sched_policy, &param);
464  }
465 #endif
466 
467  // note: this call to QThread::currentThread() may end up setting theMainThread!
468  if (QThread::currentThread() != theMainThread)
469  qWarning("WARNING: QApplication was not created in the main() thread.");
470 }
471 
473 {
474  if (threadData) {
475 #ifndef QT_NO_THREAD
476  void *data = &threadData->tls;
477  QThreadStorageData::finish((void **)data);
478 #endif
479 
480  // need to clear the state of the mainData, just in case a new QCoreApplication comes along.
481  QMutexLocker locker(&threadData->postEventList.mutex);
482  for (int i = 0; i < threadData->postEventList.size(); ++i) {
483  const QPostEvent &pe = threadData->postEventList.at(i);
484  if (pe.event) {
485  --pe.receiver->d_func()->postedEvents;
486  pe.event->posted = false;
487  delete pe.event;
488  }
489  }
490  threadData->postEventList.clear();
491  threadData->postEventList.recursion = 0;
492  threadData->quitNow = false;
493  }
494 }
495 
497 {
499 #if defined(Q_OS_SYMBIAN)
500  eventDispatcher = new QEventDispatcherSymbian(q);
501 #elif defined(Q_OS_UNIX)
502 # if defined(Q_OS_BLACKBERRY)
503  eventDispatcher = new QEventDispatcherBlackberry(q);
504 # else
505 # if !defined(QT_NO_GLIB)
506  if (qgetenv("QT_NO_GLIB").isEmpty() && QEventDispatcherGlib::versionSupported())
507  eventDispatcher = new QEventDispatcherGlib(q);
508  else
509 # endif
510  eventDispatcher = new QEventDispatcherUNIX(q);
511 # endif
512 #elif defined(Q_OS_WIN)
513  eventDispatcher = new QEventDispatcherWin32(q);
514 #else
515 # error "QEventDispatcher not yet ported to this platform"
516 #endif
517 }
518 
521 {
522  Q_ASSERT(theMainThread != 0);
523  return theMainThread;
524 }
525 
526 #if !defined (QT_NO_DEBUG) || defined (QT_MAC_FRAMEWORK_BUILD)
528 {
529  QThread *currentThread = QThread::currentThread();
530  QThread *thr = receiver->thread();
531  Q_ASSERT_X(currentThread == thr || !thr,
532  "QCoreApplication::sendEvent",
533  QString::fromLatin1("Cannot send events to objects owned by a different thread. "
534  "Current thread %1. Receiver '%2' (of type '%3') was created in thread %4")
535  .arg(QString::number((quintptr) currentThread, 16))
536  .arg(receiver->objectName())
537  .arg(QLatin1String(receiver->metaObject()->className()))
538  .arg(QString::number((quintptr) thr, 16))
539  .toLocal8Bit().data());
540  Q_UNUSED(currentThread);
541  Q_UNUSED(thr);
542 }
543 #elif defined(Q_OS_SYMBIAN) && defined (QT_NO_DEBUG)
544 // no implementation in release builds, but keep the symbol present
546 {
547 }
548 #endif
549 
551 {
552 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
553  QStringList *app_libpaths = coreappdata()->app_libpaths;
554  Q_ASSERT(app_libpaths);
555 # if defined(Q_OS_SYMBIAN)
557  // File existence check for application's private dir requires additional '\' or
558  // platform security will not allow it.
559  if (app_location != QLibraryInfo::location(QLibraryInfo::PluginsPath) && QFile::exists(app_location + QLatin1Char('\\')) && !app_libpaths->contains(app_location))
560 # else
562  app_location.truncate(app_location.lastIndexOf(QLatin1Char('/')));
563  app_location = QDir(app_location).canonicalPath();
564  if (QFile::exists(app_location) && !app_libpaths->contains(app_location))
565 # endif
566  app_libpaths->append(app_location);
567 #endif
568 }
569 
571 {
572  return *qmljs_debug_arguments();
573 }
574 
576 {
578  return QString();
579  return QCoreApplication::instance()->d_func()->appName();
580 }
581 
672  : QObject(p, 0)
673 {
674  init();
675  // note: it is the subclasses' job to call
676  // QCoreApplicationPrivate::eventDispatcher->startingUp();
677 }
678 
691 {
692  if (self && self->d_func()->eventDispatcher)
693  self->d_func()->eventDispatcher->flush();
694 }
695 
710 QCoreApplication::QCoreApplication(int &argc, char **argv)
711  : QObject(*new QCoreApplicationPrivate(argc, argv, 0x040000))
712 {
713  init();
714  QCoreApplicationPrivate::eventDispatcher->startingUp();
715 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_LIBRARY)
716  // Refresh factoryloader, as text codecs are requested during lib path
717  // resolving process and won't be therefore properly loaded.
718  // Unknown if this is symbian specific issue.
720 #endif
721 
722 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE)
723  d_func()->symbianInit();
724 #endif
725 }
726 
727 QCoreApplication::QCoreApplication(int &argc, char **argv, int _internal)
728 : QObject(*new QCoreApplicationPrivate(argc, argv, _internal))
729 {
730  init();
731  QCoreApplicationPrivate::eventDispatcher->startingUp();
732 #if defined(Q_OS_SYMBIAN)
733 #ifndef QT_NO_LIBRARY
734  // Refresh factoryloader, as text codecs are requested during lib path
735  // resolving process and won't be therefore properly loaded.
736  // Unknown if this is symbian specific issue.
738 #endif
739 #ifndef QT_NO_SYSTEMLOCALE
740  d_func()->symbianInit();
741 #endif
742 #endif //Q_OS_SYMBIAN
743 }
744 
745 
746 // ### move to QCoreApplicationPrivate constructor?
748 {
750 
751 #ifdef Q_OS_UNIX
752  setlocale(LC_ALL, ""); // use correct char set mapping
753  qt_locale_initialized = true;
754 #endif
755 
756  Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object");
757  QCoreApplication::self = this;
758 
759 #ifdef Q_OS_SYMBIAN
760  //ensure temp and working directories exist
763 #endif
764 
765 #ifndef QT_NO_THREAD
767 #endif
768 
769  // use the event dispatcher created by the app programmer (if any)
770  if (!QCoreApplicationPrivate::eventDispatcher)
771  QCoreApplicationPrivate::eventDispatcher = d->threadData->eventDispatcher;
772  // otherwise we create one
773  if (!QCoreApplicationPrivate::eventDispatcher)
774  d->createEventDispatcher();
775  Q_ASSERT(QCoreApplicationPrivate::eventDispatcher != 0);
776 
777  if (!QCoreApplicationPrivate::eventDispatcher->parent())
778  QCoreApplicationPrivate::eventDispatcher->moveToThread(d->threadData->thread);
779 
780  d->threadData->eventDispatcher = QCoreApplicationPrivate::eventDispatcher;
781 
782 #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
783  if (!coreappdata()->app_libpaths) {
784  // make sure that library paths is initialized
785  libraryPaths();
786  } else {
787  d->appendApplicationPathToLibraryPaths();
788  }
789 #endif
790 
791 #if defined(Q_OS_UNIX) && !(defined(QT_NO_PROCESS))
792  // Make sure the process manager thread object is created in the main
793  // thread.
795 #endif
796 
797 #ifdef QT_EVAL
798  extern void qt_core_eval_init(uint);
799  qt_core_eval_init(d->application_type);
800 #endif
801 
802 #if defined(Q_OS_SYMBIAN) \
803  && defined(Q_CC_NOKIAX86) \
804  && defined(QT_DEBUG)
805 
814  {
815  RLoader loader;
816  CleanupClosePushL(loader);
817  User::LeaveIfError(loader.Connect());
818  User::LeaveIfError(loader.CancelLazyDllUnload());
819  CleanupStack::PopAndDestroy(&loader);
820  }
821 #endif
822 
823  d->processCommandLineArguments();
824 
825  qt_startup_hook();
826 }
827 
828 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE)
829 void QCoreApplicationPrivate::symbianInit()
830 {
831  if (!environmentChangeNotifier)
832  environmentChangeNotifier.reset(new QEnvironmentChangeNotifier);
833 }
834 #endif
835 
836 
841 {
843 
844  self = 0;
845  QCoreApplicationPrivate::is_app_closing = true;
846  QCoreApplicationPrivate::is_app_running = false;
847 
848 #if !defined(QT_NO_THREAD)
849 #if !defined(QT_NO_CONCURRENT)
850  // Synchronize and stop the global thread pool threads.
851  QThreadPool *globalThreadPool = 0;
852  QT_TRY {
853  globalThreadPool = QThreadPool::globalInstance();
854  } QT_CATCH (...) {
855  // swallow the exception, since destructors shouldn't throw
856  }
857  if (globalThreadPool)
858  globalThreadPool->waitForDone();
859 #endif
861 #endif
862 
863  d_func()->threadData->eventDispatcher = 0;
864  if (QCoreApplicationPrivate::eventDispatcher)
865  QCoreApplicationPrivate::eventDispatcher->closingDown();
866  QCoreApplicationPrivate::eventDispatcher = 0;
867 
868 #ifndef QT_NO_LIBRARY
869  delete coreappdata()->app_libpaths;
870  coreappdata()->app_libpaths = 0;
871 #endif
872 }
873 
874 
889 {
890  if (on)
891  QCoreApplicationPrivate::attribs |= 1 << attribute;
892  else
893  QCoreApplicationPrivate::attribs &= ~(1 << attribute);
894 #ifdef Q_OS_MAC
895  // Turn on the no native menubar here, since we used to
896  // do this implicitly. We DO NOT flip it off if someone sets
897  // it to false.
898  // Ideally, we'd have magic that would be something along the lines of
899  // "follow MacPluginApplication" unless explicitly set.
900  // Considering this attribute isn't only at the beginning
901  // it's unlikely it will ever be a problem, but I want
902  // to have the behavior documented here.
903  if (attribute == Qt::AA_MacPluginApplication && on
906  }
907 #endif
908 }
909 
917 {
918  return QCoreApplicationPrivate::testAttribute(attribute);
919 }
920 
921 
929 {
930  // Make it possible for Qt Jambi and QSA to hook into events even
931  // though QApplication is subclassed...
932  bool result = false;
933  void *cbdata[] = { receiver, event, &result };
935  return result;
936  }
937 
938  // Qt enforces the rule that events can only be sent to objects in
939  // the current thread, so receiver->d_func()->threadData is
940  // equivalent to QThreadData::current(), just without the function
941  // call overhead.
942  QObjectPrivate *d = receiver->d_func();
943  QThreadData *threadData = d->threadData;
944  ++threadData->loopLevel;
945 
946 #ifdef QT_JAMBI_BUILD
947  int deleteWatch = 0;
948  int *oldDeleteWatch = QObjectPrivate::setDeleteWatch(d, &deleteWatch);
949 
950  bool inEvent = d->inEventHandler;
951  d->inEventHandler = true;
952 #endif
953 
954  bool returnValue;
955  QT_TRY {
956  returnValue = notify(receiver, event);
957  } QT_CATCH (...) {
958  --threadData->loopLevel;
959  QT_RETHROW;
960  }
961 
962 #ifdef QT_JAMBI_BUILD
963  // Restore the previous state if the object was not deleted..
964  if (!deleteWatch) {
965  d->inEventHandler = inEvent;
966  }
967  QObjectPrivate::resetDeleteWatch(d, oldDeleteWatch, deleteWatch);
968 #endif
969  --threadData->loopLevel;
970  return returnValue;
971 }
972 
973 
1017 {
1019  // no events are delivered after ~QCoreApplication() has started
1020  if (QCoreApplicationPrivate::is_app_closing)
1021  return true;
1022 
1023  if (receiver == 0) { // serious error
1024  qWarning("QCoreApplication::notify: Unexpected null receiver");
1025  return true;
1026  }
1027 
1028 #ifndef QT_NO_DEBUG
1029  d->checkReceiverThread(receiver);
1030 #endif
1031 
1032  return receiver->isWidgetType() ? false : d->notify_helper(receiver, event);
1033 }
1034 
1036 {
1037  if (receiver->d_func()->threadData == this->threadData) {
1038  // application event filters are only called for objects in the GUI thread
1039  for (int i = 0; i < eventFilters.size(); ++i) {
1040  register QObject *obj = eventFilters.at(i);
1041  if (!obj)
1042  continue;
1043  if (obj->d_func()->threadData != threadData) {
1044  qWarning("QCoreApplication: Application event filter cannot be in a different thread.");
1045  continue;
1046  }
1047  if (obj->eventFilter(receiver, event))
1048  return true;
1049  }
1050  }
1051  return false;
1052 }
1053 
1055 {
1057  if (receiver != q) {
1058  for (int i = 0; i < receiver->d_func()->eventFilters.size(); ++i) {
1059  register QObject *obj = receiver->d_func()->eventFilters.at(i);
1060  if (!obj)
1061  continue;
1062  if (obj->d_func()->threadData != receiver->d_func()->threadData) {
1063  qWarning("QCoreApplication: Object event filter cannot be in a different thread.");
1064  continue;
1065  }
1066  if (obj->eventFilter(receiver, event))
1067  return true;
1068  }
1069  }
1070  return false;
1071 }
1072 
1078 {
1079  // send to all application event filters
1080  if (sendThroughApplicationEventFilters(receiver, event))
1081  return true;
1082  // send to all receiver event filters
1083  if (sendThroughObjectEventFilters(receiver, event))
1084  return true;
1085  // deliver the event
1086  return receiver->event(event);
1087 }
1088 
1097 {
1099 }
1100 
1109 {
1111 }
1112 
1113 
1136 void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags)
1137 {
1139  if (!data->eventDispatcher)
1140  return;
1141  if (flags & QEventLoop::DeferredDeletion)
1143  data->eventDispatcher->processEvents(flags);
1144 }
1145 
1165 void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime)
1166 {
1168  if (!data->eventDispatcher)
1169  return;
1170  QElapsedTimer start;
1171  start.start();
1172  if (flags & QEventLoop::DeferredDeletion)
1175  if (start.elapsed() > maxtime)
1176  break;
1177  if (flags & QEventLoop::DeferredDeletion)
1179  }
1180 }
1181 
1182 /*****************************************************************************
1183  Main event loop wrappers
1184  *****************************************************************************/
1185 
1213 {
1215  return -1;
1216 
1217  QThreadData *threadData = self->d_func()->threadData;
1218  if (threadData != QThreadData::current()) {
1219  qWarning("%s::exec: Must be called from the main thread", self->metaObject()->className());
1220  return -1;
1221  }
1222  if (!threadData->eventLoops.isEmpty()) {
1223  qWarning("QCoreApplication::exec: The event loop is already running");
1224  return -1;
1225  }
1226 
1227  threadData->quitNow = false;
1228  QEventLoop eventLoop;
1229  self->d_func()->in_exec = true;
1230  self->d_func()->aboutToQuitEmitted = false;
1231  int returnCode = eventLoop.exec();
1232  threadData->quitNow = false;
1233  if (self) {
1234  self->d_func()->in_exec = false;
1235  if (!self->d_func()->aboutToQuitEmitted)
1236  emit self->aboutToQuit();
1237  self->d_func()->aboutToQuitEmitted = true;
1239  }
1240 
1241  return returnCode;
1242 }
1243 
1244 
1262 void QCoreApplication::exit(int returnCode)
1263 {
1264  if (!self)
1265  return;
1266  QThreadData *data = self->d_func()->threadData;
1267  data->quitNow = true;
1268  for (int i = 0; i < data->eventLoops.size(); ++i) {
1269  QEventLoop *eventLoop = data->eventLoops.at(i);
1270  eventLoop->exit(returnCode);
1271  }
1272 }
1273 
1274 /*****************************************************************************
1275  QCoreApplication management of posted events
1276  *****************************************************************************/
1277 
1316 {
1317  postEvent(receiver, event, Qt::NormalEventPriority);
1318 }
1319 
1320 
1350 void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority)
1351 {
1352  if (receiver == 0) {
1353  qWarning("QCoreApplication::postEvent: Unexpected null receiver");
1354  delete event;
1355  return;
1356  }
1357 
1358  QThreadData * volatile * pdata = &receiver->d_func()->threadData;
1359  QThreadData *data = *pdata;
1360  if (!data) {
1361  // posting during destruction? just delete the event to prevent a leak
1362  delete event;
1363  return;
1364  }
1365 
1366  // lock the post event mutex
1367  data->postEventList.mutex.lock();
1368 
1369  // if object has moved to another thread, follow it
1370  while (data != *pdata) {
1371  data->postEventList.mutex.unlock();
1372 
1373  data = *pdata;
1374  if (!data) {
1375  // posting during destruction? just delete the event to prevent a leak
1376  delete event;
1377  return;
1378  }
1379 
1380  data->postEventList.mutex.lock();
1381  }
1382 
1383  QMutexUnlocker locker(&data->postEventList.mutex);
1384 
1385  // if this is one of the compressible events, do compression
1386  if (receiver->d_func()->postedEvents
1387  && self && self->compressEvent(event, receiver, &data->postEventList)) {
1388  return;
1389  }
1390 
1391  if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) {
1392  // remember the current running eventloop for DeferredDelete
1393  // events posted in the receiver's thread
1394  event->d = reinterpret_cast<QEventPrivate *>(quintptr(data->loopLevel));
1395  }
1396 
1397  // delete the event on exceptions to protect against memory leaks till the event is
1398  // properly owned in the postEventList
1399  QScopedPointer<QEvent> eventDeleter(event);
1400  data->postEventList.addEvent(QPostEvent(receiver, event, priority));
1401  eventDeleter.take();
1402  event->posted = true;
1403  ++receiver->d_func()->postedEvents;
1404  data->canWait = false;
1405  locker.unlock();
1406 
1407  if (data->eventDispatcher)
1408  data->eventDispatcher->wakeUp();
1409 }
1410 
1419 {
1420 #ifdef Q_WS_WIN
1421  Q_ASSERT(event);
1422  Q_ASSERT(receiver);
1423  Q_ASSERT(postedEvents);
1424 
1425  // compress posted timers to this object.
1426  if (event->type() == QEvent::Timer && receiver->d_func()->postedEvents > 0) {
1427  int timerId = ((QTimerEvent *) event)->timerId();
1428  for (int i=0; i<postedEvents->size(); ++i) {
1429  const QPostEvent &e = postedEvents->at(i);
1430  if (e.receiver == receiver && e.event && e.event->type() == QEvent::Timer
1431  && ((QTimerEvent *) e.event)->timerId() == timerId) {
1432  delete event;
1433  return true;
1434  }
1435  }
1436  } else
1437 #endif
1438  if ((event->type() == QEvent::DeferredDelete
1439  || event->type() == QEvent::Quit)
1440  && receiver->d_func()->postedEvents > 0) {
1441  for (int i = 0; i < postedEvents->size(); ++i) {
1442  const QPostEvent &cur = postedEvents->at(i);
1443  if (cur.receiver != receiver
1444  || cur.event == 0
1445  || cur.event->type() != event->type())
1446  continue;
1447  // found an event for this receiver
1448  delete event;
1449  return true;
1450  }
1451  }
1452  return false;
1453 }
1454 
1481 void QCoreApplication::sendPostedEvents(QObject *receiver, int event_type)
1482 {
1484 
1485  QCoreApplicationPrivate::sendPostedEvents(receiver, event_type, data);
1486 }
1487 
1489  QThreadData *data)
1490 {
1491  if (event_type == -1) {
1492  // we were called by an obsolete event dispatcher.
1493  event_type = 0;
1494  }
1495 
1496  if (receiver && receiver->d_func()->threadData != data) {
1497  qWarning("QCoreApplication::sendPostedEvents: Cannot send "
1498  "posted events for objects in another thread");
1499  return;
1500  }
1501 
1502  ++data->postEventList.recursion;
1503 
1504 #ifdef QT3_SUPPORT
1505  if (event_type == QEvent::ChildInserted) {
1506  if (receiver) {
1507  // optimize sendPostedEvents(w, QEvent::ChildInserted) calls away
1508  receiver->d_func()->sendPendingChildInsertedEvents();
1509  --data->postEventList.recursion;
1510  return;
1511  }
1512 
1513  // ChildInserted events are sent in response to *Request
1514  event_type = QEvent::ChildInsertedRequest;
1515  }
1516 #endif
1517 
1518  QMutexLocker locker(&data->postEventList.mutex);
1519 
1520  // by default, we assume that the event dispatcher can go to sleep after
1521  // processing all events. if any new events are posted while we send
1522  // events, canWait will be set to false.
1523  data->canWait = (data->postEventList.size() == 0);
1524 
1525  if (data->postEventList.size() == 0 || (receiver && !receiver->d_func()->postedEvents)) {
1526  --data->postEventList.recursion;
1527  return;
1528  }
1529 
1530  data->canWait = true;
1531 
1532  // okay. here is the tricky loop. be careful about optimizing
1533  // this, it looks the way it does for good reasons.
1534  int startOffset = data->postEventList.startOffset;
1535  int &i = (!event_type && !receiver) ? data->postEventList.startOffset : startOffset;
1537 
1538  while (i < data->postEventList.size()) {
1539  // avoid live-lock
1540  if (i >= data->postEventList.insertionOffset)
1541  break;
1542 
1543  const QPostEvent &pe = data->postEventList.at(i);
1544  ++i;
1545 
1546  if (!pe.event)
1547  continue;
1548  if ((receiver && receiver != pe.receiver) || (event_type && event_type != pe.event->type())) {
1549  data->canWait = false;
1550  continue;
1551  }
1552 
1553  if (pe.event->type() == QEvent::DeferredDelete) {
1554  // DeferredDelete events are only sent when we are explicitly asked to
1555  // (s.a. QEvent::DeferredDelete), and then only if the event loop that
1556  // posted the event has returned.
1557  const bool allowDeferredDelete =
1558  (quintptr(pe.event->d) > unsigned(data->loopLevel)
1559  || (!quintptr(pe.event->d) && data->loopLevel > 0)
1560  || (event_type == QEvent::DeferredDelete
1561  && quintptr(pe.event->d) == unsigned(data->loopLevel)));
1562  if (!allowDeferredDelete) {
1563  // cannot send deferred delete
1564  if (!event_type && !receiver) {
1565  // don't lose the event
1566  data->postEventList.addEvent(pe);
1567  const_cast<QPostEvent &>(pe).event = 0;
1568  }
1569  continue;
1570  }
1571  }
1572 
1573  // first, we diddle the event so that we can deliver
1574  // it, and that no one will try to touch it later.
1575  pe.event->posted = false;
1576  QEvent * e = pe.event;
1577  QObject * r = pe.receiver;
1578 
1579  --r->d_func()->postedEvents;
1580  Q_ASSERT(r->d_func()->postedEvents >= 0);
1581 
1582  // next, update the data structure so that we're ready
1583  // for the next event.
1584  const_cast<QPostEvent &>(pe).event = 0;
1585 
1586  locker.unlock();
1587  // after all that work, it's time to deliver the event.
1588 #ifdef QT_NO_EXCEPTIONS
1590 #else
1591  try {
1593  } catch (...) {
1594  delete e;
1595  locker.relock();
1596 
1597  // since we were interrupted, we need another pass to make sure we clean everything up
1598  data->canWait = false;
1599 
1600  // uglehack: copied from below
1601  --data->postEventList.recursion;
1602  if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher)
1603  data->eventDispatcher->wakeUp();
1604  throw; // rethrow
1605  }
1606 #endif
1607 
1608  delete e;
1609  locker.relock();
1610 
1611  // careful when adding anything below this point - the
1612  // sendEvent() call might invalidate any invariants this
1613  // function depends on.
1614  }
1615 
1616  --data->postEventList.recursion;
1617  if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher)
1618  data->eventDispatcher->wakeUp();
1619 
1620  // clear the global list, i.e. remove everything that was
1621  // delivered.
1622  if (!event_type && !receiver && data->postEventList.startOffset >= 0) {
1624  data->postEventList.erase(it, it + data->postEventList.startOffset);
1627  data->postEventList.startOffset = 0;
1628  }
1629 }
1630 
1643 {
1644  removePostedEvents(receiver, 0);
1645 }
1646 
1669 void QCoreApplication::removePostedEvents(QObject *receiver, int eventType)
1670 {
1671 #ifdef QT3_SUPPORT
1672  if (eventType == QEvent::ChildInserted)
1673  eventType = QEvent::ChildInsertedRequest;
1674 #endif
1675 
1676  QThreadData *data = receiver ? receiver->d_func()->threadData : QThreadData::current();
1677  QMutexLocker locker(&data->postEventList.mutex);
1678 
1679  // the QObject destructor calls this function directly. this can
1680  // happen while the event loop is in the middle of posting events,
1681  // and when we get here, we may not have any more posted events
1682  // for this object.
1683  if (receiver && !receiver->d_func()->postedEvents)
1684  return;
1685 
1686  //we will collect all the posted events for the QObject
1687  //and we'll delete after the mutex was unlocked
1688  QVarLengthArray<QEvent*> events;
1689  int n = data->postEventList.size();
1690  int j = 0;
1691 
1692  for (int i = 0; i < n; ++i) {
1693  const QPostEvent &pe = data->postEventList.at(i);
1694 
1695  if ((!receiver || pe.receiver == receiver)
1696  && (pe.event && (eventType == 0 || pe.event->type() == eventType))) {
1697  --pe.receiver->d_func()->postedEvents;
1698 #ifdef QT3_SUPPORT
1699  if (pe.event->type() == QEvent::ChildInsertedRequest)
1700  pe.receiver->d_func()->pendingChildInsertedEvents.clear();
1701 #endif
1702  pe.event->posted = false;
1703  events.append(pe.event);
1704  const_cast<QPostEvent &>(pe).event = 0;
1705  } else if (!data->postEventList.recursion) {
1706  if (i != j)
1707  data->postEventList.swap(i, j);
1708  ++j;
1709  }
1710  }
1711 
1712 #ifdef QT_DEBUG
1713  if (receiver && eventType == 0) {
1714  Q_ASSERT(!receiver->d_func()->postedEvents);
1715  }
1716 #endif
1717 
1718  if (!data->postEventList.recursion) {
1719  // truncate list
1720  data->postEventList.erase(data->postEventList.begin() + j, data->postEventList.end());
1721  }
1722 
1723  locker.unlock();
1724  for (int i = 0; i < events.count(); ++i) {
1725  delete events[i];
1726  }
1727 }
1728 
1740 {
1741  if (!event || !event->posted)
1742  return;
1743 
1745 
1746  QMutexLocker locker(&data->postEventList.mutex);
1747 
1748  if (data->postEventList.size() == 0) {
1749 #if defined(QT_DEBUG)
1750  qDebug("QCoreApplication::removePostedEvent: Internal error: %p %d is posted",
1751  (void*)event, event->type());
1752  return;
1753 #endif
1754  }
1755 
1756  for (int i = 0; i < data->postEventList.size(); ++i) {
1757  const QPostEvent & pe = data->postEventList.at(i);
1758  if (pe.event == event) {
1759 #ifndef QT_NO_DEBUG
1760  qWarning("QCoreApplication::removePostedEvent: Event of type %d deleted while posted to %s %s",
1761  event->type(),
1762  pe.receiver->metaObject()->className(),
1763  pe.receiver->objectName().toLocal8Bit().data());
1764 #endif
1765  --pe.receiver->d_func()->postedEvents;
1766  pe.event->posted = false;
1767  delete pe.event;
1768  const_cast<QPostEvent &>(pe).event = 0;
1769  return;
1770  }
1771  }
1772 }
1773 
1778 {
1779  if (e->type() == QEvent::Quit) {
1780  quit();
1781  return true;
1782  }
1783  return QObject::event(e);
1784 }
1785 
1819 {
1820  exit(0);
1821 }
1822 
1841 #ifndef QT_NO_TRANSLATION
1842 
1866 {
1867  if (!translationFile)
1868  return;
1869 
1870  if (!QCoreApplicationPrivate::checkInstance("installTranslator"))
1871  return;
1872  QCoreApplicationPrivate *d = self->d_func();
1873  d->translators.prepend(translationFile);
1874 
1875 #ifndef QT_NO_TRANSLATION_BUILDER
1876  if (translationFile->isEmpty())
1877  return;
1878 #endif
1879 
1881  QCoreApplication::sendEvent(self, &ev);
1882 }
1883 
1893 {
1894  if (!translationFile)
1895  return;
1896  if (!QCoreApplicationPrivate::checkInstance("removeTranslator"))
1897  return;
1898  QCoreApplicationPrivate *d = self->d_func();
1899  if (d->translators.removeAll(translationFile) && !self->closingDown()) {
1901  QCoreApplication::sendEvent(self, &ev);
1902  }
1903 }
1904 
1908 QString QCoreApplication::translate(const char *context, const char *sourceText,
1909  const char *disambiguation, Encoding encoding)
1910 {
1911  return translate(context, sourceText, disambiguation, encoding, -1);
1912 }
1913 
1914 static void replacePercentN(QString *result, int n)
1915 {
1916  if (n >= 0) {
1917  int percentPos = 0;
1918  int len = 0;
1919  while ((percentPos = result->indexOf(QLatin1Char('%'), percentPos + len)) != -1) {
1920  len = 1;
1921  QString fmt;
1922  if (result->at(percentPos + len) == QLatin1Char('L')) {
1923  ++len;
1924  fmt = QLatin1String("%L1");
1925  } else {
1926  fmt = QLatin1String("%1");
1927  }
1928  if (result->at(percentPos + len) == QLatin1Char('n')) {
1929  fmt = fmt.arg(n);
1930  ++len;
1931  result->replace(percentPos, len, fmt);
1932  len = fmt.length();
1933  }
1934  }
1935  }
1936 }
1937 
1986 QString QCoreApplication::translate(const char *context, const char *sourceText,
1987  const char *disambiguation, Encoding encoding, int n)
1988 {
1989  QString result;
1990 
1991  if (!sourceText)
1992  return result;
1993 
1994  if (self && !self->d_func()->translators.isEmpty()) {
1996  QTranslator *translationFile;
1997  for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) {
1998  translationFile = *it;
1999  result = translationFile->translate(context, sourceText, disambiguation, n);
2000  if (!result.isEmpty())
2001  break;
2002  }
2003  }
2004 
2005  if (result.isEmpty()) {
2006 #ifdef QT_NO_TEXTCODEC
2007  Q_UNUSED(encoding)
2008 #else
2009  if (encoding == UnicodeUTF8)
2010  result = QString::fromUtf8(sourceText);
2011  else if (QTextCodec::codecForTr() != 0)
2012  result = QTextCodec::codecForTr()->toUnicode(sourceText);
2013  else
2014 #endif
2015  result = QString::fromLatin1(sourceText);
2016  }
2017 
2018  replacePercentN(&result, n);
2019  return result;
2020 }
2021 
2022 // Declared in qglobal.h
2023 QString qtTrId(const char *id, int n)
2024 {
2026 }
2027 
2029 {
2030  return QCoreApplication::self
2031  && QCoreApplication::self->d_func()->translators.contains(translator);
2032 }
2033 
2034 #endif //QT_NO_TRANSLATE
2035 
2061 {
2062  if (!self) {
2063  qWarning("QCoreApplication::applicationDirPath: Please instantiate the QApplication object first");
2064  return QString();
2065  }
2066 
2067  QCoreApplicationPrivate *d = self->d_func();
2069 #if defined(Q_OS_SYMBIAN)
2070  {
2071  QString appPath;
2072  RFs& fs = qt_s60GetRFs();
2073  TChar driveChar;
2074  QChar qDriveChar;
2075  driveChar = (RProcess().FileName())[0];
2076 
2077  //Check if the process is installed in a read only drive (typically ROM),
2078  //and use the system drive (typically C:) if so.
2079  TInt drive;
2080  TDriveInfo driveInfo;
2081  TInt err = fs.CharToDrive(driveChar, drive);
2082  if (err == KErrNone) {
2083  err = fs.Drive(driveInfo, drive);
2084  }
2085  if (err != KErrNone || (driveInfo.iDriveAtt & KDriveAttRom) || (driveInfo.iMediaAtt
2086  & KMediaAttWriteProtected)) {
2087  drive = fs.GetSystemDrive();
2088  fs.DriveToChar(drive, driveChar);
2089  }
2090 
2091  qDriveChar = QChar(QLatin1Char(driveChar)).toUpper();
2092 
2093  TFileName privatePath;
2094  fs.PrivatePath(privatePath);
2095  appPath = qt_TDesC2QString(privatePath);
2096  appPath.prepend(QLatin1Char(':')).prepend(qDriveChar);
2097 
2098  d->cachedApplicationDirPath = QFileInfo(appPath).path();
2099  }
2100 #else
2102 #endif
2103  return d->cachedApplicationDirPath;
2104 }
2105 
2122 {
2123  if (!self) {
2124  qWarning("QCoreApplication::applicationFilePath: Please instantiate the QApplication object first");
2125  return QString();
2126  }
2127 
2128  QCoreApplicationPrivate *d = self->d_func();
2130  return d->cachedApplicationFilePath;
2131 
2132 #if defined(Q_WS_WIN)
2134  return d->cachedApplicationFilePath;
2135 #elif defined(Q_OS_BLACKBERRY)
2136  if (!arguments().isEmpty()) { // args is never empty, but the navigator can change behaviour some day
2137  QFileInfo fileInfo(arguments().at(0));
2138  const bool zygotized = fileInfo.exists();
2139  if (zygotized) {
2140  // Handle the zygotized case:
2142  return d->cachedApplicationFilePath;
2143  }
2144  }
2145 
2146  // Handle the non-zygotized case:
2147  const size_t maximum_path = static_cast<size_t>(pathconf("/",_PC_PATH_MAX));
2148  char buff[maximum_path+1];
2149  if (_cmdname(buff)) {
2151  return d->cachedApplicationFilePath;
2152  } else {
2153  qWarning("QCoreApplication::applicationFilePath: _cmdname() failed");
2154  // _cmdname() won't fail, but just in case, fallback to the old method
2155  QDir dir(QLatin1String("./app/native/"));
2156  QStringList executables = dir.entryList(QDir::Executable | QDir::Files);
2157  if (!executables.empty()) {
2158  //We assume that there is only one executable in the folder
2159  d->cachedApplicationFilePath = dir.absoluteFilePath(executables.first());
2160  return d->cachedApplicationFilePath;
2161  } else {
2162  return QString();
2163  }
2164  }
2165 #elif defined(Q_WS_MAC)
2166  QString qAppFileName_str = qAppFileName();
2167  if(!qAppFileName_str.isEmpty()) {
2168  QFileInfo fi(qAppFileName_str);
2170  return d->cachedApplicationFilePath;
2171  }
2172 #endif
2173 #if defined(Q_OS_SYMBIAN)
2174  QString appPath;
2175  RProcess proc;
2176  TInt err = proc.Open(proc.Id());
2177  if (err == KErrNone) {
2178  TFileName procName = proc.FileName();
2179  appPath.append(QString(reinterpret_cast<const QChar*>(procName.Ptr()), procName.Length()));
2180  proc.Close();
2181  }
2182 
2183  d->cachedApplicationFilePath = appPath;
2184  return d->cachedApplicationFilePath;
2185 
2186 #elif defined( Q_OS_UNIX )
2187 # ifdef Q_OS_LINUX
2188  // Try looking for a /proc/<pid>/exe symlink first which points to
2189  // the absolute path of the executable
2190  QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid()));
2191  if (pfi.exists() && pfi.isSymLink()) {
2193  return d->cachedApplicationFilePath;
2194  }
2195 # endif
2196 
2197  QString argv0 = QFile::decodeName(QByteArray(argv()[0]));
2198  QString absPath;
2199 
2200  if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
2201  /*
2202  If argv0 starts with a slash, it is already an absolute
2203  file path.
2204  */
2205  absPath = argv0;
2206  } else if (argv0.contains(QLatin1Char('/'))) {
2207  /*
2208  If argv0 contains one or more slashes, it is a file path
2209  relative to the current directory.
2210  */
2211  absPath = QDir::current().absoluteFilePath(argv0);
2212  } else {
2213  /*
2214  Otherwise, the file path has to be determined using the
2215  PATH environment variable.
2216  */
2217  QByteArray pEnv = qgetenv("PATH");
2218  QDir currentDir = QDir::current();
2220  for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
2221  if ((*p).isEmpty())
2222  continue;
2223  QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0);
2224  QFileInfo candidate_fi(candidate);
2225  if (candidate_fi.exists() && !candidate_fi.isDir()) {
2226  absPath = candidate;
2227  break;
2228  }
2229  }
2230  }
2231 
2232  absPath = QDir::cleanPath(absPath);
2233 
2234  QFileInfo fi(absPath);
2236  return d->cachedApplicationFilePath;
2237 #endif
2238 }
2239 
2249 {
2250 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
2251  return GetCurrentProcessId();
2252 #elif defined(Q_OS_VXWORKS)
2253  return (pid_t) taskIdCurrent;
2254 #else
2255  return getpid();
2256 #endif
2257 }
2258 
2268 {
2269  if (!self) {
2270  qWarning("QCoreApplication::argc: Please instantiate the QApplication object first");
2271  return 0;
2272  }
2273  return self->d_func()->argc;
2274 }
2275 
2276 
2286 {
2287  if (!self) {
2288  qWarning("QCoreApplication::argv: Please instantiate the QApplication object first");
2289  return 0;
2290  }
2291  return self->d_func()->argv;
2292 }
2293 
2334 {
2335  QStringList list;
2336 
2337  if (!self) {
2338  qWarning("QCoreApplication::arguments: Please instantiate the QApplication object first");
2339  return list;
2340  }
2341 #ifdef Q_OS_WIN
2342  QString cmdline = QString::fromWCharArray(GetCommandLine());
2343 
2344 #if defined(Q_OS_WINCE)
2345  wchar_t tempFilename[MAX_PATH+1];
2346  if (GetModuleFileName(0, tempFilename, MAX_PATH)) {
2347  tempFilename[MAX_PATH] = 0;
2348  cmdline.prepend(QLatin1Char('\"') + QString::fromWCharArray(tempFilename) + QLatin1String("\" "));
2349  }
2350 #endif // Q_OS_WINCE
2351 
2352  list = qWinCmdArgs(cmdline);
2353  if (self->d_func()->application_type) { // GUI app? Skip known - see qapplication.cpp
2355  for (int a = 0; a < list.count(); ++a) {
2356  QString arg = list.at(a);
2357  QByteArray l1arg = arg.toLatin1();
2358  if (l1arg == "-qdevel" ||
2359  l1arg == "-qdebug" ||
2360  l1arg == "-reverse" ||
2361  l1arg == "-stylesheet" ||
2362  l1arg == "-widgetcount")
2363  ;
2364  else if (l1arg.startsWith("-style=") ||
2365  l1arg.startsWith("-qmljsdebugger="))
2366  ;
2367  else if (l1arg == "-style" ||
2368  l1arg == "-qmljsdebugger" ||
2369  l1arg == "-session" ||
2370  l1arg == "-graphicssystem" ||
2371  l1arg == "-testability")
2372  ++a;
2373  else
2374  stripped += arg;
2375  }
2376  list = stripped;
2377  }
2378 #else
2379  const int ac = self->d_func()->argc;
2380  char ** const av = self->d_func()->argv;
2381  for (int a = 0; a < ac; ++a) {
2382  list << QString::fromLocal8Bit(av[a]);
2383  }
2384 #endif
2385 
2386  return list;
2387 }
2388 
2412 {
2413  coreappdata()->orgName = orgName;
2414 }
2415 
2417 {
2418 #ifdef Q_OS_BLACKBERRY
2419  coreappdata()->loadManifest();
2420 #endif
2421  return coreappdata()->orgName;
2422 }
2423 
2443 {
2444  coreappdata()->orgDomain = orgDomain;
2445 }
2446 
2448 {
2449  return coreappdata()->orgDomain;
2450 }
2451 
2469 {
2470  coreappdata()->application = application;
2471 }
2472 
2474 {
2475 #ifdef Q_OS_BLACKBERRY
2476  coreappdata()->loadManifest();
2477 #endif
2478 
2479  QString appname = coreappdata() ? coreappdata()->application : QString();
2480  if (appname.isEmpty() && QCoreApplication::self)
2481  appname = QCoreApplication::self->d_func()->appName();
2482 
2483  return appname;
2484 }
2485 
2500 {
2501  coreappdata()->applicationVersion = version;
2502 }
2503 
2505 {
2506 #ifdef Q_OS_BLACKBERRY
2507  coreappdata()->loadManifest();
2508 #endif
2509  return coreappdata()->applicationVersion;
2510 }
2511 
2512 #ifndef QT_NO_LIBRARY
2513 
2514 #if defined(Q_OS_SYMBIAN)
2515 void qt_symbian_installLibraryPaths(QString installPathPlugins, QStringList& libPaths)
2516 {
2517  // Add existing path on all drives for relative PluginsPath in Symbian
2518  QString tempPath = installPathPlugins;
2519  if (tempPath.at(tempPath.length() - 1) != QDir::separator()) {
2520  tempPath += QDir::separator();
2521  }
2522  RFs& fs = qt_s60GetRFs();
2523  TPtrC tempPathPtr(reinterpret_cast<const TText*> (tempPath.constData()));
2524  // Symbian searches should start from Y:. Fix start drive otherwise TFindFile starts from the session drive
2525  _LIT(KStartDir, "Y:");
2526  TFileName dirPath(KStartDir);
2527  dirPath.Append(tempPathPtr);
2528  TFindFile finder(fs);
2529  TInt err = finder.FindByDir(tempPathPtr, dirPath);
2530  while (err == KErrNone) {
2531  QString foundDir(reinterpret_cast<const QChar *>(finder.File().Ptr()),
2532  finder.File().Length());
2533  foundDir = QDir(foundDir).canonicalPath();
2534  if (!libPaths.contains(foundDir))
2535  libPaths.append(foundDir);
2536  err = finder.Find();
2537  }
2538 }
2539 #endif
2540 
2542 
2543 
2567 {
2568  QMutexLocker locker(libraryPathMutex());
2569  if (!coreappdata()->app_libpaths) {
2570  QStringList *app_libpaths = coreappdata()->app_libpaths = new QStringList;
2572 #if defined(Q_OS_SYMBIAN)
2573  if (installPathPlugins.at(1) != QChar(QLatin1Char(':'))) {
2574  qt_symbian_installLibraryPaths(installPathPlugins, *app_libpaths);
2575  }
2576 #else
2577  if (QFile::exists(installPathPlugins)) {
2578  // Make sure we convert from backslashes to slashes.
2579  installPathPlugins = QDir(installPathPlugins).canonicalPath();
2580  if (!app_libpaths->contains(installPathPlugins))
2581  app_libpaths->append(installPathPlugins);
2582  }
2583 #endif
2584 
2585  // If QCoreApplication is not yet instantiated,
2586  // make sure we add the application path when we construct the QCoreApplication
2587  if (self) self->d_func()->appendApplicationPathToLibraryPaths();
2588 
2589  const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
2590  if (!libPathEnv.isEmpty()) {
2591 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
2592  QLatin1Char pathSep(';');
2593 #else
2594  QLatin1Char pathSep(':');
2595 #endif
2596  QStringList paths = QString::fromLatin1(libPathEnv).split(pathSep, QString::SkipEmptyParts);
2597  for (QStringList::const_iterator it = paths.constBegin(); it != paths.constEnd(); ++it) {
2598  QString canonicalPath = QDir(*it).canonicalPath();
2599  if (!canonicalPath.isEmpty()
2600  && !app_libpaths->contains(canonicalPath)) {
2601  app_libpaths->append(canonicalPath);
2602  }
2603  }
2604  }
2605  }
2606  return *(coreappdata()->app_libpaths);
2607 }
2608 
2609 
2610 
2624 {
2625  QMutexLocker locker(libraryPathMutex());
2626  if (!coreappdata()->app_libpaths)
2627  coreappdata()->app_libpaths = new QStringList;
2628  *(coreappdata()->app_libpaths) = paths;
2629  locker.unlock();
2631 }
2632 
2650 {
2651  if (path.isEmpty())
2652  return;
2653 
2654  QMutexLocker locker(libraryPathMutex());
2655 
2656  // make sure that library paths is initialized
2657  libraryPaths();
2658 
2659  QString canonicalPath = QDir(path).canonicalPath();
2660  if (!canonicalPath.isEmpty()
2661  && !coreappdata()->app_libpaths->contains(canonicalPath)) {
2662  coreappdata()->app_libpaths->prepend(canonicalPath);
2663  locker.unlock();
2665  }
2666 }
2667 
2675 {
2676  if (path.isEmpty())
2677  return;
2678 
2679  QMutexLocker locker(libraryPathMutex());
2680 
2681  // make sure that library paths is initialized
2682  libraryPaths();
2683 
2684  QString canonicalPath = QDir(path).canonicalPath();
2685  coreappdata()->app_libpaths->removeAll(canonicalPath);
2687 }
2688 
2689 #if defined(Q_OS_SYMBIAN)
2690 void QCoreApplicationPrivate::rebuildInstallLibraryPaths()
2691 {
2692  // check there is not a single fixed install path
2693  QString nativeInstallPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath);
2694  if (nativeInstallPathPlugins.at(1) == QChar(QLatin1Char(':')))
2695  return;
2696  QString installPathPlugins = QDir::cleanPath(nativeInstallPathPlugins);
2697  // look for the install path at the drive roots
2698  installPathPlugins.prepend(QChar(QLatin1Char(':')));
2699 
2700  QMutexLocker locker(libraryPathMutex());
2701  QStringList &app_libpaths = *coreappdata()->app_libpaths;
2702  // Build a new library path, copying non-installPath components, and replacing existing install path with new
2703  QStringList newPaths;
2704  bool installPathFound = false;
2705  foreach (QString path, app_libpaths) {
2706  if (path.mid(1).compare(installPathPlugins, Qt::CaseInsensitive) == 0) {
2707  // skip existing install paths, insert new install path when we find the first
2708  if (!installPathFound)
2709  qt_symbian_installLibraryPaths(nativeInstallPathPlugins, newPaths);
2710  installPathFound = true;
2711  } else {
2712  newPaths.append(path);
2713  }
2714  }
2715  app_libpaths = newPaths;
2716 }
2717 #endif
2718 
2719 #endif //QT_NO_LIBRARY
2720 
2773 {
2775  EventFilter old = d->eventFilter;
2776  d->eventFilter = filter;
2777  return old;
2778 }
2779 
2788 bool QCoreApplication::filterEvent(void *message, long *result)
2789 {
2791  if (result)
2792  *result = 0;
2793  if (d->eventFilter)
2794  return d->eventFilter(message, result);
2795 #ifdef Q_OS_WIN
2796  return winEventFilter(reinterpret_cast<MSG *>(message), result);
2797 #else
2798  return false;
2799 #endif
2800 }
2801 
2810 {
2812  if (eventDispatcher)
2813  return eventDispatcher->hasPendingEvents();
2814  return false;
2815 }
2816 
2817 #ifdef QT3_SUPPORT
2818 
2895 int QCoreApplication::enter_loop()
2896 {
2897  if (!QCoreApplicationPrivate::checkInstance("enter_loop"))
2898  return -1;
2899  if (QThreadData::current() != self->d_func()->threadData) {
2900  qWarning("QCoreApplication::enter_loop: Must be called from the main thread");
2901  return -1;
2902  }
2903  QEventLoop eventLoop;
2904  int returnCode = eventLoop.exec();
2905  return returnCode;
2906 }
2907 
2916 void QCoreApplication::exit_loop()
2917 {
2918  if (!QCoreApplicationPrivate::checkInstance("exit_loop"))
2919  return;
2921  if (data != self->d_func()->threadData) {
2922  qWarning("QCoreApplication::exit_loop: Must be called from the main thread");
2923  return;
2924  }
2925  if (!data->eventLoops.isEmpty())
2926  data->eventLoops.top()->exit();
2927 }
2928 
2936 int QCoreApplication::loopLevel()
2937 {
2938  if (!QCoreApplicationPrivate::checkInstance("loopLevel"))
2939  return -1;
2940  return self->d_func()->threadData->eventLoops.size();
2941 }
2942 #endif
2943 
2944 /*
2945  \fn void QCoreApplication::watchUnixSignal(int signal, bool watch)
2946  \internal
2947 */
2948 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
static void removeLibraryPath(const QString &)
Removes path from the library path list.
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
static QT_DEPRECATED int argc()
Use arguments().
static void refreshAll()
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QString qtTrId(const char *id, int n)
bool sendThroughApplicationEventFilters(QObject *, QEvent *)
static bool checkInstance(const char *method)
static void cleanup()
Cleans up the QThread system.
Definition: qthread.cpp:661
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
static QStringList qWinCmdArgs(QString cmdLine)
Encoding
This enum type defines the 8-bit encoding of character string arguments to translate(): ...
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
static void finish(void **)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
void qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set)
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
Definition: qdir.cpp:701
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define it(className, varName)
void qAddPostRoutine(QtCleanUpFunction p)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
static QString applicationFilePath()
Returns the file path of the application executable.
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
static QString qmljsDebugArguments()
static glyph_t stripped(glyph_t glyph)
static void removeTranslator(QTranslator *messageFile)
Removes the translation file translationFile from the list of translation files used by this applicat...
QString objectName
the name of this object
Definition: qobject.h:114
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
#define at(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
#define Q_WS_WIN
Defined on Windows.
Definition: qglobal.h:921
QString & prepend(QChar c)
Definition: qstring.h:261
T * take()
Returns the value of the pointer referenced by this object.
bool empty() const
This function is provided for STL compatibility.
Definition: qlist.h:304
static int exec()
Enters the main event loop and waits until exit() is called.
static void addLibraryPath(const QString &)
Prepends path to the beginning of the library path list, ensuring that it is searched for libraries f...
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
static bool testAttribute(uint flag)
void addEvent(const QPostEvent &ev)
Definition: qthread_p.h:115
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
bool canWait
Definition: qthread_p.h:267
static QThread * theMainThread
bool destroyed
Definition: qglobal.h:1943
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
bool notify_helper(QObject *, QEvent *)
EventFilter setEventFilter(EventFilter filter)
Replaces the event filter function for the QCoreApplication with filter and returns the pointer to th...
static QString macMenuBarName()
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
The QString class provides a Unicode character string.
Definition: qstring.h:83
void appendApplicationPathToLibraryPaths(void)
static QT_DEPRECATED char ** argv()
Use arguments() instead.
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *)
Returns true if event was compressed away (possibly deleted) and should not be added to the list...
QString qAppFileName()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static void installTranslator(QTranslator *messageFile)
Adds the translation file translationFile to the list of translation files to be used for translation...
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
void Q_CORE_EXPORT qt_call_post_routines()
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_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
QThreadData * threadData
Definition: qobject_p.h:195
void append(const T &t)
static void replacePercentN(QString *result, int n)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
QString qAppName()
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
void deref()
Definition: qthread.cpp:125
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_Q(Class)
Definition: qglobal.h:2483
static QFileSystemEntry currentPath()
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
void relock()
Relocks an unlocked mutex locker.
Definition: qmutex.h:125
Q_CORE_EXPORT void qDebug(const char *,...)
static void quit()
Tells the application to exit with return code 0 (success).
QByteArray right(int len) const
Returns a byte array that contains the rightmost len bytes of this byte array.
friend class const_iterator
Definition: qlist.h:264
#define QT_RETHROW
Definition: qglobal.h:1539
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static QThreadData * get2(QThread *thread)
Definition: qthread_p.h:219
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual bool notify(QObject *, QEvent *)
Sends event to receiver: {receiver}->event(event).
static QString applicationDirPath()
Returns the directory that contains the application executable.
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
The QThreadPool class manages a collection of QThreads.
Definition: qthreadpool.h:58
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void initializeProcessManager()
virtual QString appName() const
int loopLevel
Definition: qthread_p.h:263
static bool isEmpty(const char *str)
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
static bool activateCallbacks(Callback, void **)
Definition: qglobal.cpp:3653
void waitForDone()
Waits for each thread to exit and removes all threads from the thread pool.
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_GLOBAL_STATIC_WITH_ARGS(QSettings, staticTrolltechConf,(QSettings::UserScope, QLatin1String("Trolltech"))) QSettings *QCoreApplicationPrivate
static char * aargv[]
QCoreApplication(int &argc, char **argv)
Constructs a Qt kernel application.
void checkReceiverThread(QObject *receiver)
QMutex mutex
Definition: qthread_p.h:109
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
static void setOrganizationDomain(const QString &orgDomain)
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
static QDir current()
Returns the application&#39;s current directory.
Definition: qdir.h:209
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QMutexUnlocker(QMutex *m)
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
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
QBasicAtomicPointer< T > pointer
Definition: qglobal.h:1942
Q_CORE_EXPORT void qWarning(const char *,...)
static qint64 applicationPid()
Returns the current process ID for the application.
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
void qt_set_current_thread_to_main_thread()
QPostEventList postEventList
Definition: qthread_p.h:266
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
static void split(QT_FT_Vector *b)
static void sendPostedEvents()
friend class iterator
Definition: qlist.h:226
virtual void wakeUp()=0
Wakes up the event loop.
static QTextCodec * codecForTr()
Returns the codec used by QObject::tr() on its argument.
Definition: qtextcodec.h:155
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
static void setOrganizationName(const QString &orgName)
void * HANDLE
Definition: qnamespace.h:1671
ushort posted
Definition: qcoreevent.h:319
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
int count() const
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
#define QT_CATCH(A)
Definition: qglobal.h:1537
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
bool quitNow
Definition: qthread_p.h:262
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
virtual void createEventDispatcher()
void aboutToQuit()
This signal is emitted when the application is about to quit the main event loop, e...
static void setApplicationVersion(const QString &version)
static bool hasPendingEvents()
This function returns true if there are pending events; otherwise returns false.
const void * CFTypeRef
uint inEventHandler
Definition: qobject.h:102
ApplicationAttribute
Definition: qnamespace.h:536
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
static bool startingUp()
Returns true if an application object has not been created yet; otherwise returns false...
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
int length() const
Same as size().
Definition: qbytearray.h:356
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QEventPrivate * d
Definition: qcoreevent.h:315
The QTranslator class provides internationalization support for text output.
Definition: qtranslator.h:59
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QEvent * event
Definition: qthread_p.h:78
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
The QCoreApplication class provides an event loop for console Qt applications.
virtual QString translate(const char *context, const char *sourceText, const char *disambiguation=0) const
Returns the translation for the key (context, sourceText, disambiguation).
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
Definition: qeventloop.cpp:288
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QString & append(QChar c)
Definition: qstring.cpp:1777
int compare(const QString &s) const
Definition: qstring.cpp:5037
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static QString applicationVersion()
virtual bool hasPendingEvents()=0
Returns true if there is an event waiting; otherwise returns false.
QObject * receiver
Definition: qthread_p.h:77
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
static QAbstractEventDispatcher * eventDispatcher
static QThread * mainThread()
virtual bool processEvents(QEventLoop::ProcessEventsFlags flags)=0
Processes pending events that match flags until there are no more events to process.
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
int insertionOffset
Definition: qthread_p.h:107
void Q_CORE_EXPORT qt_startup_hook()
virtual bool isEmpty() const
Returns true if this translator is empty, otherwise returns false.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
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
~QCoreApplication()
Destroys the QCoreApplication object.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
static QStringList libraryPaths()
Returns a list of paths that the application will search when dynamically loading libraries...
static QString location(LibraryLocation)
Returns the location specified by loc.
static bool isTranslatorInstalled(QTranslator *translator)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool notifyInternal(QObject *receiver, QEvent *event)
bool(* EventFilter)(void *message, long *result)
A function with the following signature that can be used as an event filter:
Q_GLOBAL_STATIC(QString, qmljs_debug_arguments)
static void exit(int retcode=0)
Tells the application to exit with a return code.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString canonicalPath() const
Returns the canonical path, i.e.
Definition: qdir.cpp:642
static void cleanup()
Definition: qpicture.cpp:1508
QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
static void initialize()
Definition: qthread.cpp:643
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
static QString organizationDomain()
QList< QtCleanUpFunction > QVFuncList
static QThreadData * current()
static QString organizationName()
friend class QCoreApplicationPrivate
Definition: qobject.h:328
static void setApplicationName(const QString &application)
static void setLibraryPaths(const QStringList &)
Sets the list of directories to search when loading libraries to paths.
static int aargc
static QCoreApplication * self
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
Q_CORE_EXPORT bool qt_locale_initialized
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
static QStringList arguments()
Returns the list of command-line arguments.
removePostedEvents
Removes all events of the given eventType that were posted using postEvent() for receiver.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
static QString applicationName()
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
QString path() const
Returns the file&#39;s path.
Definition: qfileinfo.cpp:615
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
bool filterEvent(void *message, long *result)
Sends message through the event filter that was set by setEventFilter().
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
void qRemovePostRoutine(QtCleanUpFunction p)
bool atEnd() const
Returns true if the end of the file has been reached; otherwise returns false.
Definition: qfile.cpp:1735
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
Definition: qfileinfo.cpp:707
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
bool sendThroughObjectEventFilters(QObject *, QEvent *)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
#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
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264
static QMutex * globalInstanceGet(const void *address)
Returns a QMutex from the global mutex pool.
Definition: qmutexpool.cpp:150
void start()
Starts this timer.
#define QT_TRY
Definition: qglobal.h:1536
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of the names of all the files and directories in the directory, ordered according to t...
Definition: qdir.cpp:1290
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void swap(QList< T > &other)
Swaps list other with this list.
Definition: qlist.h:129
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
Qt::HANDLE qt_application_thread_id
static void flush()
Flushes the platform specific event queues.
virtual bool winEventFilter(MSG *message, long *result)
The message procedure calls this function for every message received.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void(* QtCleanUpFunction)()
static void removePostedEvent(QEvent *)
Removes event from the queue of posted events, and emits a warning message if appropriate.
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.
QStack< QEventLoop * > eventLoops
Definition: qthread_p.h:265
#define Q_FUNC_INFO
Definition: qglobal.h:1871