| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | #include "qcoreapplication.h" | - | ||||||||||||||||||||||||
| 42 | #include "qcoreapplication_p.h" | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 45 | #include "qabstracteventdispatcher.h" | - | ||||||||||||||||||||||||
| 46 | #include "qcoreevent.h" | - | ||||||||||||||||||||||||
| 47 | #include "qeventloop.h" | - | ||||||||||||||||||||||||
| 48 | #endif | - | ||||||||||||||||||||||||
| 49 | #include "qcorecmdlineargs_p.h" | - | ||||||||||||||||||||||||
| 50 | #include <qdatastream.h> | - | ||||||||||||||||||||||||
| 51 | #include <qdebug.h> | - | ||||||||||||||||||||||||
| 52 | #include <qdir.h> | - | ||||||||||||||||||||||||
| 53 | #include <qfile.h> | - | ||||||||||||||||||||||||
| 54 | #include <qfileinfo.h> | - | ||||||||||||||||||||||||
| 55 | #include <qmutex.h> | - | ||||||||||||||||||||||||
| 56 | #include <private/qloggingregistry_p.h> | - | ||||||||||||||||||||||||
| 57 | #include <qstandardpaths.h> | - | ||||||||||||||||||||||||
| 58 | #include <qtextcodec.h> | - | ||||||||||||||||||||||||
| 59 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 60 | #include <qthread.h> | - | ||||||||||||||||||||||||
| 61 | #include <qthreadpool.h> | - | ||||||||||||||||||||||||
| 62 | #include <qthreadstorage.h> | - | ||||||||||||||||||||||||
| 63 | #include <private/qthread_p.h> | - | ||||||||||||||||||||||||
| 64 | #endif | - | ||||||||||||||||||||||||
| 65 | #include <qelapsedtimer.h> | - | ||||||||||||||||||||||||
| 66 | #include <qlibraryinfo.h> | - | ||||||||||||||||||||||||
| 67 | #include <qvarlengtharray.h> | - | ||||||||||||||||||||||||
| 68 | #include <private/qfactoryloader_p.h> | - | ||||||||||||||||||||||||
| 69 | #include <private/qfunctions_p.h> | - | ||||||||||||||||||||||||
| 70 | #include <private/qlocale_p.h> | - | ||||||||||||||||||||||||
| 71 | #include <private/qhooks_p.h> | - | ||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||
| 73 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 74 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 75 | # if defined(Q_OS_BLACKBERRY) | - | ||||||||||||||||||||||||
| # include "qeventdispatcher_blackberry_p.h" | ||||||||||||||||||||||||||
| # include <process.h> | ||||||||||||||||||||||||||
| # include <unistd.h> | ||||||||||||||||||||||||||
| # elifdefined(Q_OS_OSX) | ||||||||||||||||||||||||||
| 76 | # include "qeventdispatcher_cf_p.h" | - | ||||||||||||||||||||||||
| # include "qeventdispatcher_unix_p.h" | ||||||||||||||||||||||||||
| 77 | # else | - | ||||||||||||||||||||||||
| 78 | # if !defined(QT_NO_GLIB) | - | ||||||||||||||||||||||||
| 79 | # include "qeventdispatcher_glib_p.h" | - | ||||||||||||||||||||||||
| 80 | # endif | - | ||||||||||||||||||||||||
| 81 | # endif | - | ||||||||||||||||||||||||
| 82 | # include "qeventdispatcher_unix_p.h" | - | ||||||||||||||||||||||||
| # endif#endif | ||||||||||||||||||||||||||
| 84 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 85 | # ifdef Q_OS_WINRT | - | ||||||||||||||||||||||||
| 86 | # include "qeventdispatcher_winrt_p.h" | - | ||||||||||||||||||||||||
| 87 | # include "qfunctions_winrt.h" | - | ||||||||||||||||||||||||
| 88 | # include <wrl.h> | - | ||||||||||||||||||||||||
| 89 | # include <Windows.ApplicationModel.core.h> | - | ||||||||||||||||||||||||
| 90 | using namespace ABI::Windows::ApplicationModel::Core; | - | ||||||||||||||||||||||||
| 91 | using namespace Microsoft::WRL; | - | ||||||||||||||||||||||||
| 92 | # else | - | ||||||||||||||||||||||||
| 93 | # include "qeventdispatcher_win_p.h" | - | ||||||||||||||||||||||||
| 94 | # endif | - | ||||||||||||||||||||||||
| 95 | #endif | - | ||||||||||||||||||||||||
| 96 | #endif // QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 99 | # include "qcore_mac_p.h" | - | ||||||||||||||||||||||||
| 100 | #endif | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | #include <stdlib.h> | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||||||||
| 105 | # include <locale.h> | - | ||||||||||||||||||||||||
| 106 | # include <unistd.h> | - | ||||||||||||||||||||||||
| 107 | # include <sys/types.h> | - | ||||||||||||||||||||||||
| 108 | #endif | - | ||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||
| 110 | #ifdef Q_OS_VXWORKS | - | ||||||||||||||||||||||||
| 111 | # include <taskLib.h> | - | ||||||||||||||||||||||||
| 112 | #endif | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | #include <algorithm> | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 119 | class QMutexUnlocker | - | ||||||||||||||||||||||||
| 120 | { | - | ||||||||||||||||||||||||
| 121 | public: | - | ||||||||||||||||||||||||
| 122 | inline explicit QMutexUnlocker(QMutex *m) | - | ||||||||||||||||||||||||
| 123 | : mtx(m) | - | ||||||||||||||||||||||||
| 124 | { } | - | ||||||||||||||||||||||||
| 125 | inline ~QMutexUnlocker() { unlock(); } | - | ||||||||||||||||||||||||
| 126 | inline void unlock() { if (mtx) mtx->unlock(); mtx = 0; } | - | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | private: | - | ||||||||||||||||||||||||
| 129 | Q_DISABLE_COPY(QMutexUnlocker) | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | QMutex *mtx; | - | ||||||||||||||||||||||||
| 132 | }; | - | ||||||||||||||||||||||||
| 133 | #endif | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | #if defined(Q_OS_WIN) || defined(Q_OS_MAC) | - | ||||||||||||||||||||||||
| 136 | extern QString qAppFileName(); | - | ||||||||||||||||||||||||
| 137 | #endif | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | #if QT_VERSION >= 0x060000 | - | ||||||||||||||||||||||||
| 140 | # error "Bump QCoreApplicatoinPrivate::app_compile_version to 0x060000" | - | ||||||||||||||||||||||||
| 141 | #endif | - | ||||||||||||||||||||||||
| 142 | int QCoreApplicationPrivate::app_compile_version = 0x050000; //we don't know exactly, but it's at least 5.0.0 | - | ||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||
| 144 | bool QCoreApplicationPrivate::setuidAllowed = false; | - | ||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | #if !defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 147 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 148 | QString QCoreApplicationPrivate::macMenuBarName() | - | ||||||||||||||||||||||||
| 149 | { | - | ||||||||||||||||||||||||
| 150 | QString bundleName; | - | ||||||||||||||||||||||||
| 151 | CFTypeRef string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("CFBundleName")); | - | ||||||||||||||||||||||||
| 152 | if (string) | - | ||||||||||||||||||||||||
| 153 | bundleName = QCFString::toQString(static_cast<CFStringRef>(string)); | - | ||||||||||||||||||||||||
| 154 | return bundleName; | - | ||||||||||||||||||||||||
| 155 | } | - | ||||||||||||||||||||||||
| 156 | #endif | - | ||||||||||||||||||||||||
| 157 | QString QCoreApplicationPrivate::appName() const | - | ||||||||||||||||||||||||
| 158 | { | - | ||||||||||||||||||||||||
| 159 | QString applicationName; | - | ||||||||||||||||||||||||
| 160 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 161 | applicationName = macMenuBarName(); | - | ||||||||||||||||||||||||
| 162 | #endif | - | ||||||||||||||||||||||||
| 163 | if (applicationName.isEmpty() && argv[0]) { | - | ||||||||||||||||||||||||
| 164 | char *p = strrchr(argv[0], '/'); | - | ||||||||||||||||||||||||
| 165 | applicationName = QString::fromLocal8Bit(p ? p + 1 : argv[0]); | - | ||||||||||||||||||||||||
| 166 | } | - | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | return applicationName; | - | ||||||||||||||||||||||||
| 169 | } | - | ||||||||||||||||||||||||
| 170 | #endif | - | ||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||
| 172 | QString *QCoreApplicationPrivate::cachedApplicationFilePath = 0; | - | ||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | bool QCoreApplicationPrivate::checkInstance(const char *function) | - | ||||||||||||||||||||||||
| 175 | { | - | ||||||||||||||||||||||||
| 176 | bool b = (QCoreApplication::self != 0); | - | ||||||||||||||||||||||||
| 177 | if (!b) | - | ||||||||||||||||||||||||
| 178 | qWarning("QApplication::%s: Please instantiate the QApplication object first", function); | - | ||||||||||||||||||||||||
| 179 | return b; | - | ||||||||||||||||||||||||
| 180 | } | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | void QCoreApplicationPrivate::processCommandLineArguments() | - | ||||||||||||||||||||||||
| 183 | { | - | ||||||||||||||||||||||||
| 184 | int j = argc ? 1 : 0; | - | ||||||||||||||||||||||||
| 185 | for (int i = 1; i < argc; ++i) { | - | ||||||||||||||||||||||||
| 186 | if (!argv[i]) | - | ||||||||||||||||||||||||
| 187 | continue; | - | ||||||||||||||||||||||||
| 188 | if (*argv[i] != '-') { | - | ||||||||||||||||||||||||
| 189 | argv[j++] = argv[i]; | - | ||||||||||||||||||||||||
| 190 | continue; | - | ||||||||||||||||||||||||
| 191 | } | - | ||||||||||||||||||||||||
| 192 | const char *arg = argv[i]; | - | ||||||||||||||||||||||||
| 193 | if (arg[1] == '-') // startsWith("--") | - | ||||||||||||||||||||||||
| 194 | ++arg; | - | ||||||||||||||||||||||||
| 195 | if (strncmp(arg, "-qmljsdebugger=", 15) == 0) { | - | ||||||||||||||||||||||||
| 196 | qmljs_debug_arguments = QString::fromLocal8Bit(arg + 15); | - | ||||||||||||||||||||||||
| 197 | } else if (strcmp(arg, "-qmljsdebugger") == 0 && i < argc - 1) { | - | ||||||||||||||||||||||||
| 198 | ++i; | - | ||||||||||||||||||||||||
| 199 | qmljs_debug_arguments = QString::fromLocal8Bit(argv[i]); | - | ||||||||||||||||||||||||
| 200 | } else { | - | ||||||||||||||||||||||||
| 201 | argv[j++] = argv[i]; | - | ||||||||||||||||||||||||
| 202 | } | - | ||||||||||||||||||||||||
| 203 | } | - | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | if (j < argc) { | - | ||||||||||||||||||||||||
| 206 | argv[j] = 0; | - | ||||||||||||||||||||||||
| 207 | argc = j; | - | ||||||||||||||||||||||||
| 208 | } | - | ||||||||||||||||||||||||
| 209 | } | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | // Support for introspection | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 214 | QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set = { 0, 0, 0, 0 }; | - | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | void qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set) | - | ||||||||||||||||||||||||
| 217 | { | - | ||||||||||||||||||||||||
| 218 | qt_signal_spy_callback_set = callback_set; | - | ||||||||||||||||||||||||
| 219 | } | - | ||||||||||||||||||||||||
| 220 | #endif | - | ||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | extern "C" void Q_CORE_EXPORT qt_startup_hook() | - | ||||||||||||||||||||||||
| 223 | { | - | ||||||||||||||||||||||||
| 224 | } | - | ||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | typedef QList<QtStartUpFunction> QStartUpFuncList; | - | ||||||||||||||||||||||||
| 227 | Q_GLOBAL_STATIC(QStartUpFuncList, preRList) | - | ||||||||||||||||||||||||
| 228 | typedef QList<QtCleanUpFunction> QVFuncList; | - | ||||||||||||||||||||||||
| 229 | Q_GLOBAL_STATIC(QVFuncList, postRList) | - | ||||||||||||||||||||||||
| 230 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 231 | static QBasicMutex globalPreRoutinesMutex; | - | ||||||||||||||||||||||||
| 232 | #endif | - | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | /*! | - | ||||||||||||||||||||||||
| 235 | \internal | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | Adds a global routine that will be called from the QCoreApplication | - | ||||||||||||||||||||||||
| 238 | constructor. The public API is Q_COREAPP_STARTUP_FUNCTION. | - | ||||||||||||||||||||||||
| 239 | */ | - | ||||||||||||||||||||||||
| 240 | void qAddPreRoutine(QtStartUpFunction p) | - | ||||||||||||||||||||||||
| 241 | { | - | ||||||||||||||||||||||||
| 242 | QStartUpFuncList *list = preRList(); | - | ||||||||||||||||||||||||
| 243 | if (!list) | - | ||||||||||||||||||||||||
| 244 | return; | - | ||||||||||||||||||||||||
| 245 | // Due to C++11 parallel dynamic initialization, this can be called | - | ||||||||||||||||||||||||
| 246 | // from multiple threads. | - | ||||||||||||||||||||||||
| 247 | #ifndef QT_NO_THREAD | - | ||||||||||||||||||||||||
| 248 | QMutexLocker locker(&globalPreRoutinesMutex); | - | ||||||||||||||||||||||||
| 249 | #endif | - | ||||||||||||||||||||||||
| 250 | if (QCoreApplication::instance()) | - | ||||||||||||||||||||||||
| 251 | p(); | - | ||||||||||||||||||||||||
| 252 | list->prepend(p); // in case QCoreApplication is re-created, see qt_call_pre_routines | - | ||||||||||||||||||||||||
| 253 | } | - | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | void qAddPostRoutine(QtCleanUpFunction p) | - | ||||||||||||||||||||||||
| 256 | { | - | ||||||||||||||||||||||||
| 257 | QVFuncList *list = postRList(); | - | ||||||||||||||||||||||||
| 258 | if (!list) | - | ||||||||||||||||||||||||
| 259 | return; | - | ||||||||||||||||||||||||
| 260 | list->prepend(p); | - | ||||||||||||||||||||||||
| 261 | } | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | void qRemovePostRoutine(QtCleanUpFunction p) | - | ||||||||||||||||||||||||
| 264 | { | - | ||||||||||||||||||||||||
| 265 | QVFuncList *list = postRList(); | - | ||||||||||||||||||||||||
| 266 | if (!list) | - | ||||||||||||||||||||||||
| 267 | return; | - | ||||||||||||||||||||||||
| 268 | list->removeAll(p); | - | ||||||||||||||||||||||||
| 269 | } | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | static void qt_call_pre_routines() | - | ||||||||||||||||||||||||
| 272 | { | - | ||||||||||||||||||||||||
| 273 | QStartUpFuncList *list = preRList(); | - | ||||||||||||||||||||||||
| 274 | if (!list) | - | ||||||||||||||||||||||||
| 275 | return; | - | ||||||||||||||||||||||||
| 276 | #ifndef QT_NO_THREAD | - | ||||||||||||||||||||||||
| 277 | QMutexLocker locker(&globalPreRoutinesMutex); | - | ||||||||||||||||||||||||
| 278 | #endif | - | ||||||||||||||||||||||||
| 279 | // Unlike qt_call_post_routines, we don't empty the list, because | - | ||||||||||||||||||||||||
| 280 | // Q_COREAPP_STARTUP_FUNCTION is a macro, so the user expects | - | ||||||||||||||||||||||||
| 281 | // the function to be executed every time QCoreApplication is created. | - | ||||||||||||||||||||||||
| 282 | for (int i = 0; i < list->count(); ++i) | - | ||||||||||||||||||||||||
| 283 | list->at(i)(); | - | ||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | void Q_CORE_EXPORT qt_call_post_routines() | - | ||||||||||||||||||||||||
| 287 | { | - | ||||||||||||||||||||||||
| 288 | QVFuncList *list = 0; | - | ||||||||||||||||||||||||
| 289 | QT_TRY { | - | ||||||||||||||||||||||||
| 290 | list = postRList(); | - | ||||||||||||||||||||||||
| 291 | } QT_CATCH(const std::bad_alloc &) { | - | ||||||||||||||||||||||||
| 292 | // ignore - if we can't allocate a post routine list, | - | ||||||||||||||||||||||||
| 293 | // there's a high probability that there's no post | - | ||||||||||||||||||||||||
| 294 | // routine to be executed :) | - | ||||||||||||||||||||||||
| 295 | } | - | ||||||||||||||||||||||||
| 296 | if (!list) | - | ||||||||||||||||||||||||
| 297 | return; | - | ||||||||||||||||||||||||
| 298 | while (!list->isEmpty()) | - | ||||||||||||||||||||||||
| 299 | (list->takeFirst())(); | - | ||||||||||||||||||||||||
| 300 | } | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | // initialized in qcoreapplication and in qtextstream autotest when setlocale is called. | - | ||||||||||||||||||||||||
| 304 | static bool qt_locale_initialized = false; | - | ||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||
| 306 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | // app starting up if false | - | ||||||||||||||||||||||||
| 309 | bool QCoreApplicationPrivate::is_app_running = false; | - | ||||||||||||||||||||||||
| 310 | // app closing down if true | - | ||||||||||||||||||||||||
| 311 | bool QCoreApplicationPrivate::is_app_closing = false; | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | Q_CORE_EXPORT uint qGlobalPostedEventsCount() | - | ||||||||||||||||||||||||
| 314 | { | - | ||||||||||||||||||||||||
| 315 | QThreadData *currentThreadData = QThreadData::current(); | - | ||||||||||||||||||||||||
| 316 | return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; | - | ||||||||||||||||||||||||
| 317 | } | - | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0; | - | ||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||||||||
| 322 | Qt::HANDLE qt_application_thread_id = 0; | - | ||||||||||||||||||||||||
| 323 | #endif | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | #endif // QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | QCoreApplication *QCoreApplication::self = 0; | - | ||||||||||||||||||||||||
| 328 | uint QCoreApplicationPrivate::attribs = | - | ||||||||||||||||||||||||
| 329 | (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents) | | - | ||||||||||||||||||||||||
| 330 | (1 << Qt::AA_SynthesizeMouseForUnhandledTabletEvents); | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | struct QCoreApplicationData { | - | ||||||||||||||||||||||||
| 333 | QCoreApplicationData() Q_DECL_NOTHROW { | - | ||||||||||||||||||||||||
| 334 | applicationNameSet = false; | - | ||||||||||||||||||||||||
| 335 | } executed 850 times by 25 tests: end of blockExecuted by:
| 850 | ||||||||||||||||||||||||
| 336 | ~QCoreApplicationData() { | - | ||||||||||||||||||||||||
| 337 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 338 | // cleanup the QAdoptedThread created for the main() thread | - | ||||||||||||||||||||||||
| 339 | if (QCoreApplicationPrivate::theMainThread) { | - | ||||||||||||||||||||||||
| 340 | QThreadData *data = QThreadData::get2(QCoreApplicationPrivate::theMainThread); | - | ||||||||||||||||||||||||
| 341 | data->deref(); // deletes the data and the adopted thread | - | ||||||||||||||||||||||||
| 342 | } | - | ||||||||||||||||||||||||
| 343 | #endif | - | ||||||||||||||||||||||||
| 344 | } | - | ||||||||||||||||||||||||
| #ifdef Q_OS_BLACKBERRY | ||||||||||||||||||||||||||
| void loadManifest() { | ||||||||||||||||||||||||||
| static bool manifestLoadAttempt = false; | ||||||||||||||||||||||||||
| if (manifestLoadAttempt) | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| manifestLoadAttempt = true; | ||||||||||||||||||||||||||
| QFile metafile(QStringLiteral("app/META-INF/MANIFEST.MF")); | ||||||||||||||||||||||||||
| if (!metafile.open(QIODevice::ReadOnly)) { | ||||||||||||||||||||||||||
| qWarning("Could not open application metafile for reading") | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| while (!metafile.atEnd() && (application.isEmpty() || applicationVersion.isEmpty() || orgName.isEmpty())) { | ||||||||||||||||||||||||||
| QByteArray line = metafile.readLine(); | ||||||||||||||||||||||||||
| if (line.startsWith("Application-Name:")) | ||||||||||||||||||||||||||
| application = QString::fromUtf8(line.mid(18).trimmed()); | ||||||||||||||||||||||||||
| else if (line.startsWith("Application-Version:")) | ||||||||||||||||||||||||||
| applicationVersion = QString::fromUtf8(line.mid(21).trimmed()); | ||||||||||||||||||||||||||
| else if (line.startsWith("Package-Author:")) | ||||||||||||||||||||||||||
| orgName = QString::fromUtf8(line.mid(16).trimmed()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| metafile.close(); | ||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | #endifQString orgName, orgDomain; | - | ||||||||||||||||||||||||
| 347 | QString application; // application name, initially from argv[0], can then be modified. | - | ||||||||||||||||||||||||
| 348 | QString applicationVersion; | - | ||||||||||||||||||||||||
| 349 | bool applicationNameSet; // true if setApplicationName was called | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 352 | QScopedPointer<QStringList> app_libpaths; | - | ||||||||||||||||||||||||
| 353 | QScopedPointer<QStringList> manual_libpaths; | - | ||||||||||||||||||||||||
| 354 | #endif | - | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | }; | - | ||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||
| 358 | Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata) | - | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 361 | static bool quitLockRefEnabled = true; | - | ||||||||||||||||||||||||
| 362 | #endif | - | ||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||
| 364 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 365 | // Check whether the command line arguments match those passed to main() | - | ||||||||||||||||||||||||
| 366 | // by comparing to the global __argv/__argc (MS extension). | - | ||||||||||||||||||||||||
| 367 | // Deep comparison is required since argv/argc is rebuilt by WinMain for | - | ||||||||||||||||||||||||
| 368 | // GUI apps or when using MinGW due to its globbing. | - | ||||||||||||||||||||||||
| 369 | static inline bool isArgvModified(int argc, char **argv) | - | ||||||||||||||||||||||||
| 370 | { | - | ||||||||||||||||||||||||
| 371 | if (__argc != argc || !__argv /* wmain() */) | - | ||||||||||||||||||||||||
| 372 | return true; | - | ||||||||||||||||||||||||
| 373 | if (__argv == argv) | - | ||||||||||||||||||||||||
| 374 | return false; | - | ||||||||||||||||||||||||
| 375 | for (int a = 0; a < argc; ++a) { | - | ||||||||||||||||||||||||
| 376 | if (argv[a] != __argv[a] && strcmp(argv[a], __argv[a])) | - | ||||||||||||||||||||||||
| 377 | return true; | - | ||||||||||||||||||||||||
| 378 | } | - | ||||||||||||||||||||||||
| 379 | return false; | - | ||||||||||||||||||||||||
| 380 | } | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | static inline bool contains(int argc, char **argv, const char *needle) | - | ||||||||||||||||||||||||
| 383 | { | - | ||||||||||||||||||||||||
| 384 | for (int a = 0; a < argc; ++a) { | - | ||||||||||||||||||||||||
| 385 | if (!strcmp(argv[a], needle)) | - | ||||||||||||||||||||||||
| 386 | return true; | - | ||||||||||||||||||||||||
| 387 | } | - | ||||||||||||||||||||||||
| 388 | return false; | - | ||||||||||||||||||||||||
| 389 | } | - | ||||||||||||||||||||||||
| 390 | #endif // Q_OS_WIN && !Q_OS_WINRT | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint flags) | - | ||||||||||||||||||||||||
| 393 | : | - | ||||||||||||||||||||||||
| 394 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 395 | QObjectPrivate(), | - | ||||||||||||||||||||||||
| 396 | #endif | - | ||||||||||||||||||||||||
| 397 | argc(aargc) | - | ||||||||||||||||||||||||
| 398 | , argv(aargv) | - | ||||||||||||||||||||||||
| 399 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 400 | , origArgc(0) | - | ||||||||||||||||||||||||
| 401 | , origArgv(Q_NULLPTR) | - | ||||||||||||||||||||||||
| 402 | #endif | - | ||||||||||||||||||||||||
| 403 | , application_type(QCoreApplicationPrivate::Tty) | - | ||||||||||||||||||||||||
| 404 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 405 | , in_exec(false) | - | ||||||||||||||||||||||||
| 406 | , aboutToQuitEmitted(false) | - | ||||||||||||||||||||||||
| 407 | , threadData_clean(false) | - | ||||||||||||||||||||||||
| 408 | #else | - | ||||||||||||||||||||||||
| 409 | , q_ptr(0) | - | ||||||||||||||||||||||||
| 410 | #endif | - | ||||||||||||||||||||||||
| 411 | { | - | ||||||||||||||||||||||||
| 412 | app_compile_version = flags & 0xffffff; | - | ||||||||||||||||||||||||
| 413 | static const char *const empty = ""; | - | ||||||||||||||||||||||||
| 414 | if (argc == 0 || argv == 0) {
| 0-980 | ||||||||||||||||||||||||
| 415 | argc = 0; | - | ||||||||||||||||||||||||
| 416 | argv = const_cast<char **>(&empty); | - | ||||||||||||||||||||||||
| 417 | } executed 98 times by 6 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||||||||
| 418 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 419 | if (!isArgvModified(argc, argv)) { | - | ||||||||||||||||||||||||
| 420 | origArgc = argc; | - | ||||||||||||||||||||||||
| 421 | origArgv = new char *[argc]; | - | ||||||||||||||||||||||||
| 422 | std::copy(argv, argv + argc, QT_MAKE_CHECKED_ARRAY_ITERATOR(origArgv, argc)); | - | ||||||||||||||||||||||||
| 423 | } | - | ||||||||||||||||||||||||
| 424 | #endif // Q_OS_WIN && !Q_OS_WINRT | - | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 427 | QCoreApplicationPrivate::is_app_closing = false; | - | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | # if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 430 | if (Q_UNLIKELY(!setuidAllowed && (geteuid() != getuid()))())))
| 0-1078 | ||||||||||||||||||||||||
| 431 | qFatal("FATAL: The application binary appears to be running setuid, this is a security hole."); never executed: QMessageLogger(__FILE__, 431, __PRETTY_FUNCTION__).fatal("FATAL: The application binary appears to be running setuid, this is a security hole."); | 0 | ||||||||||||||||||||||||
| 432 | # endif // Q_OS_UNIX | - | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | # if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 435 | qt_application_thread_id = QThread::currentThreadId(); | - | ||||||||||||||||||||||||
| 436 | # endif | - | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | QThread *cur = QThread::currentThread(); // note: this may end up setting theMainThread! | - | ||||||||||||||||||||||||
| 439 | if (cur != theMainThread)
| 0-1078 | ||||||||||||||||||||||||
| 440 | qWarning("WARNING: QApplication was not created in the main() thread."); never executed: QMessageLogger(__FILE__, 440, __PRETTY_FUNCTION__).warning("WARNING: QApplication was not created in the main() thread."); | 0 | ||||||||||||||||||||||||
| 441 | #endif | - | ||||||||||||||||||||||||
| 442 | } executed 1078 times by 23 tests: end of blockExecuted by:
| 1078 | ||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | QCoreApplicationPrivate::~QCoreApplicationPrivate() | - | ||||||||||||||||||||||||
| 445 | { | - | ||||||||||||||||||||||||
| 446 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 447 | cleanupThreadData(); | - | ||||||||||||||||||||||||
| 448 | #endif | - | ||||||||||||||||||||||||
| 449 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 450 | delete [] origArgv; | - | ||||||||||||||||||||||||
| 451 | #endif | - | ||||||||||||||||||||||||
| 452 | QCoreApplicationPrivate::clearApplicationFilePath(); | - | ||||||||||||||||||||||||
| 453 | } | - | ||||||||||||||||||||||||
| 454 | - | |||||||||||||||||||||||||
| 455 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | void QCoreApplicationPrivate::cleanupThreadData() | - | ||||||||||||||||||||||||
| 458 | { | - | ||||||||||||||||||||||||
| 459 | if (threadData && !threadData_clean) { | - | ||||||||||||||||||||||||
| 460 | #ifndef QT_NO_THREAD | - | ||||||||||||||||||||||||
| 461 | void *data = &threadData->tls; | - | ||||||||||||||||||||||||
| 462 | QThreadStorageData::finish((void **)data); | - | ||||||||||||||||||||||||
| 463 | #endif | - | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | // need to clear the state of the mainData, just in case a new QCoreApplication comes along. | - | ||||||||||||||||||||||||
| 466 | QMutexLocker locker(&threadData->postEventList.mutex); | - | ||||||||||||||||||||||||
| 467 | for (int i = 0; i < threadData->postEventList.size(); ++i) { | - | ||||||||||||||||||||||||
| 468 | const QPostEvent &pe = threadData->postEventList.at(i); | - | ||||||||||||||||||||||||
| 469 | if (pe.event) { | - | ||||||||||||||||||||||||
| 470 | --pe.receiver->d_func()->postedEvents; | - | ||||||||||||||||||||||||
| 471 | pe.event->posted = false; | - | ||||||||||||||||||||||||
| 472 | delete pe.event; | - | ||||||||||||||||||||||||
| 473 | } | - | ||||||||||||||||||||||||
| 474 | } | - | ||||||||||||||||||||||||
| 475 | threadData->postEventList.clear(); | - | ||||||||||||||||||||||||
| 476 | threadData->postEventList.recursion = 0; | - | ||||||||||||||||||||||||
| 477 | threadData->quitNow = false; | - | ||||||||||||||||||||||||
| 478 | threadData_clean = true; | - | ||||||||||||||||||||||||
| 479 | } | - | ||||||||||||||||||||||||
| 480 | } | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | void QCoreApplicationPrivate::createEventDispatcher() | - | ||||||||||||||||||||||||
| 483 | { | - | ||||||||||||||||||||||||
| 484 | Q_Q(QCoreApplication); | - | ||||||||||||||||||||||||
| 485 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 486 | # if defined(Q_OS_BLACKBERRY) | - | ||||||||||||||||||||||||
| eventDispatcher = new QEventDispatcherBlackberry(q); | ||||||||||||||||||||||||||
| # elifdefined(Q_OS_OSX) | ||||||||||||||||||||||||||
| 487 | bool ok = false; | - | ||||||||||||||||||||||||
| 488 | int value = qEnvironmentVariableIntValue("QT_EVENT_DISPATCHER_CORE_FOUNDATION", &ok); | - | ||||||||||||||||||||||||
| 489 | if (ok && value > 0) | - | ||||||||||||||||||||||||
| 490 | eventDispatcher = new QEventDispatcherCoreFoundation(q); | - | ||||||||||||||||||||||||
| 491 | else | - | ||||||||||||||||||||||||
| 492 | eventDispatcher = new QEventDispatcherUNIX(q); | - | ||||||||||||||||||||||||
| 493 | # elif !defined(QT_NO_GLIB) | - | ||||||||||||||||||||||||
| 494 | if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && QEventDispatcherGlib::versionSupported())
| 0-940 | ||||||||||||||||||||||||
| 495 | eventDispatcher = new QEventDispatcherGlib(q); executed 940 times by 22 tests: eventDispatcher = new QEventDispatcherGlib(q);Executed by:
| 940 | ||||||||||||||||||||||||
| 496 | else | - | ||||||||||||||||||||||||
| 497 | eventDispatcher = new QEventDispatcherUNIX(q); never executed: eventDispatcher = new QEventDispatcherUNIX(q); | 0 | ||||||||||||||||||||||||
| 498 | # else | - | ||||||||||||||||||||||||
| 499 | eventDispatcher = new QEventDispatcherUNIX(q); | - | ||||||||||||||||||||||||
| 500 | # endif | - | ||||||||||||||||||||||||
| 501 | #elif defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 502 | eventDispatcher = new QEventDispatcherWinRT(q); | - | ||||||||||||||||||||||||
| 503 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 504 | eventDispatcher = new QEventDispatcherWin32(q); | - | ||||||||||||||||||||||||
| 505 | #else | - | ||||||||||||||||||||||||
| 506 | # error "QEventDispatcher not yet ported to this platform" | - | ||||||||||||||||||||||||
| 507 | #endif | - | ||||||||||||||||||||||||
| 508 | } | - | ||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | void QCoreApplicationPrivate::eventDispatcherReady() | - | ||||||||||||||||||||||||
| 511 | { | - | ||||||||||||||||||||||||
| 512 | } | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0); | - | ||||||||||||||||||||||||
| 515 | QThread *QCoreApplicationPrivate::mainThread() | - | ||||||||||||||||||||||||
| 516 | { | - | ||||||||||||||||||||||||
| 517 | Q_ASSERT(theMainThread.load() != 0); | - | ||||||||||||||||||||||||
| 518 | return theMainThread.load(); | - | ||||||||||||||||||||||||
| 519 | } | - | ||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||
| 521 | bool QCoreApplicationPrivate::threadRequiresCoreApplication() | - | ||||||||||||||||||||||||
| 522 | { | - | ||||||||||||||||||||||||
| 523 | QThreadData *data = QThreadData::current(false); | - | ||||||||||||||||||||||||
| 524 | if (!data) | - | ||||||||||||||||||||||||
| 525 | return true; // default setting | - | ||||||||||||||||||||||||
| 526 | return data->requiresCoreApplication; | - | ||||||||||||||||||||||||
| 527 | } | - | ||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||
| 529 | void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver) | - | ||||||||||||||||||||||||
| 530 | { | - | ||||||||||||||||||||||||
| 531 | QThread *currentThread = QThread::currentThread(); | - | ||||||||||||||||||||||||
| 532 | QThread *thr = receiver->thread(); | - | ||||||||||||||||||||||||
| 533 | Q_ASSERT_X(currentThread == thr || !thr, | - | ||||||||||||||||||||||||
| 534 | "QCoreApplication::sendEvent", | - | ||||||||||||||||||||||||
| 535 | QString::fromLatin1("Cannot send events to objects owned by a different thread. " | - | ||||||||||||||||||||||||
| 536 | "Current thread %1. Receiver '%2' (of type '%3') was created in thread %4") | - | ||||||||||||||||||||||||
| 537 | .arg(QString::number((quintptr) currentThread, 16)) | - | ||||||||||||||||||||||||
| 538 | .arg(receiver->objectName()) | - | ||||||||||||||||||||||||
| 539 | .arg(QLatin1String(receiver->metaObject()->className())) | - | ||||||||||||||||||||||||
| 540 | .arg(QString::number((quintptr) thr, 16)) | - | ||||||||||||||||||||||||
| 541 | .toLocal8Bit().data()); | - | ||||||||||||||||||||||||
| 542 | Q_UNUSED(currentThread); | - | ||||||||||||||||||||||||
| 543 | Q_UNUSED(thr); | - | ||||||||||||||||||||||||
| 544 | } | - | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | #endif // QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths() | - | ||||||||||||||||||||||||
| 549 | { | - | ||||||||||||||||||||||||
| 550 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 551 | QStringList *app_libpaths = coreappdata()->app_libpaths.data(); | - | ||||||||||||||||||||||||
| 552 | if (!app_libpaths) | - | ||||||||||||||||||||||||
| 553 | coreappdata()->app_libpaths.reset(app_libpaths = new QStringList); | - | ||||||||||||||||||||||||
| 554 | QString app_location = QCoreApplication::applicationFilePath(); | - | ||||||||||||||||||||||||
| 555 | app_location.truncate(app_location.lastIndexOf(QLatin1Char('/'))); | - | ||||||||||||||||||||||||
| 556 | #ifdef Q_OS_WINRT | - | ||||||||||||||||||||||||
| 557 | if (app_location.isEmpty()) | - | ||||||||||||||||||||||||
| 558 | app_location.append(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 559 | #endif | - | ||||||||||||||||||||||||
| 560 | app_location = QDir(app_location).canonicalPath(); | - | ||||||||||||||||||||||||
| 561 | if (QFile::exists(app_location) && !app_libpaths->contains(app_location)) | - | ||||||||||||||||||||||||
| 562 | app_libpaths->append(app_location); | - | ||||||||||||||||||||||||
| 563 | #endif | - | ||||||||||||||||||||||||
| 564 | } | - | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | QString qAppName() | - | ||||||||||||||||||||||||
| 567 | { | - | ||||||||||||||||||||||||
| 568 | if (!QCoreApplicationPrivate::checkInstance("qAppName")) | - | ||||||||||||||||||||||||
| 569 | return QString(); | - | ||||||||||||||||||||||||
| 570 | return QCoreApplication::instance()->d_func()->appName(); | - | ||||||||||||||||||||||||
| 571 | } | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | void QCoreApplicationPrivate::initLocale() | - | ||||||||||||||||||||||||
| 574 | { | - | ||||||||||||||||||||||||
| 575 | if (qt_locale_initialized)
| 230-848 | ||||||||||||||||||||||||
| 576 | return; executed 230 times by 8 tests: return;Executed by:
| 230 | ||||||||||||||||||||||||
| 577 | qt_locale_initialized = true; | - | ||||||||||||||||||||||||
| #ifdef#if defined(Q_OS_UNIX) && !defined(QT_BOOTSTRAPPED) | ||||||||||||||||||||||||||
| 579 | setlocale(LC_ALL, ""); | - | ||||||||||||||||||||||||
| 580 | #endif | - | ||||||||||||||||||||||||
| 581 | } executed 848 times by 23 tests: end of blockExecuted by:
| 848 | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | /*! | - | ||||||||||||||||||||||||
| 585 | \class QCoreApplication | - | ||||||||||||||||||||||||
| 586 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 587 | \brief The QCoreApplication class provides an event loop for Qt | - | ||||||||||||||||||||||||
| 588 | applications without UI. | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | This class is used by non-GUI applications to provide their event | - | ||||||||||||||||||||||||
| 591 | loop. For non-GUI application that uses Qt, there should be exactly | - | ||||||||||||||||||||||||
| 592 | one QCoreApplication object. For GUI applications, see | - | ||||||||||||||||||||||||
| 593 | QGuiApplication. For applications that use the Qt Widgets module, | - | ||||||||||||||||||||||||
| 594 | see QApplication. | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | QCoreApplication contains the main event loop, where all events | - | ||||||||||||||||||||||||
| 597 | from the operating system (e.g., timer and network events) and | - | ||||||||||||||||||||||||
| 598 | other sources are processed and dispatched. It also handles the | - | ||||||||||||||||||||||||
| 599 | application's initialization and finalization, as well as | - | ||||||||||||||||||||||||
| 600 | system-wide and application-wide settings. | - | ||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||
| 602 | \section1 The Event Loop and Event Handling | - | ||||||||||||||||||||||||
| 603 | - | |||||||||||||||||||||||||
| 604 | The event loop is started with a call to exec(). Long-running | - | ||||||||||||||||||||||||
| 605 | operations can call processEvents() to keep the application | - | ||||||||||||||||||||||||
| 606 | responsive. | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | In general, we recommend that you create a QCoreApplication, | - | ||||||||||||||||||||||||
| 609 | QGuiApplication or a QApplication object in your \c main() | - | ||||||||||||||||||||||||
| 610 | function as early as possible. exec() will not return until | - | ||||||||||||||||||||||||
| 611 | the event loop exits; e.g., when quit() is called. | - | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | Several static convenience functions are also provided. The | - | ||||||||||||||||||||||||
| 614 | QCoreApplication object is available from instance(). Events can | - | ||||||||||||||||||||||||
| 615 | be sent or posted using sendEvent(), postEvent(), and | - | ||||||||||||||||||||||||
| 616 | sendPostedEvents(). Pending events can be removed with | - | ||||||||||||||||||||||||
| 617 | removePostedEvents() or flushed with flush(). | - | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | The class provides a quit() slot and an aboutToQuit() signal. | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | \section1 Application and Library Paths | - | ||||||||||||||||||||||||
| 622 | - | |||||||||||||||||||||||||
| 623 | An application has an applicationDirPath() and an | - | ||||||||||||||||||||||||
| 624 | applicationFilePath(). Library paths (see QLibrary) can be retrieved | - | ||||||||||||||||||||||||
| 625 | with libraryPaths() and manipulated by setLibraryPaths(), addLibraryPath(), | - | ||||||||||||||||||||||||
| 626 | and removeLibraryPath(). | - | ||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||
| 628 | \section1 Internationalization and Translations | - | ||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | Translation files can be added or removed | - | ||||||||||||||||||||||||
| 631 | using installTranslator() and removeTranslator(). Application | - | ||||||||||||||||||||||||
| 632 | strings can be translated using translate(). The QObject::tr() | - | ||||||||||||||||||||||||
| 633 | and QObject::trUtf8() functions are implemented in terms of | - | ||||||||||||||||||||||||
| 634 | translate(). | - | ||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | \section1 Accessing Command Line Arguments | - | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | The command line arguments which are passed to QCoreApplication's | - | ||||||||||||||||||||||||
| 639 | constructor should be accessed using the arguments() function. | - | ||||||||||||||||||||||||
| 640 | - | |||||||||||||||||||||||||
| 641 | \note QCoreApplication removes option \c -qmljsdebugger="...". It parses the | - | ||||||||||||||||||||||||
| 642 | argument of \c qmljsdebugger, and then removes this option plus its argument. | - | ||||||||||||||||||||||||
| 643 | - | |||||||||||||||||||||||||
| 644 | For more advanced command line option handling, create a QCommandLineParser. | - | ||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||
| 646 | \section1 Locale Settings | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | On Unix/Linux Qt is configured to use the system locale settings by | - | ||||||||||||||||||||||||
| 649 | default. This can cause a conflict when using POSIX functions, for | - | ||||||||||||||||||||||||
| 650 | instance, when converting between data types such as floats and | - | ||||||||||||||||||||||||
| 651 | strings, since the notation may differ between locales. To get | - | ||||||||||||||||||||||||
| 652 | around this problem, call the POSIX function \c{setlocale(LC_NUMERIC,"C")} | - | ||||||||||||||||||||||||
| 653 | right after initializing QApplication, QGuiApplication or QCoreApplication | - | ||||||||||||||||||||||||
| 654 | to reset the locale that is used for number formatting to "C"-locale. | - | ||||||||||||||||||||||||
| 655 | - | |||||||||||||||||||||||||
| 656 | \sa QGuiApplication, QAbstractEventDispatcher, QEventLoop, | - | ||||||||||||||||||||||||
| 657 | {Semaphores Example}, {Wait Conditions Example} | - | ||||||||||||||||||||||||
| 658 | */ | - | ||||||||||||||||||||||||
| 659 | - | |||||||||||||||||||||||||
| 660 | /*! | - | ||||||||||||||||||||||||
| 661 | \fn static QCoreApplication *QCoreApplication::instance() | - | ||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||
| 663 | Returns a pointer to the application's QCoreApplication (or | - | ||||||||||||||||||||||||
| 664 | QGuiApplication/QApplication) instance. | - | ||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||
| 666 | If no instance has been allocated, \c null is returned. | - | ||||||||||||||||||||||||
| 667 | */ | - | ||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||
| 669 | /*! | - | ||||||||||||||||||||||||
| 670 | \internal | - | ||||||||||||||||||||||||
| 671 | */ | - | ||||||||||||||||||||||||
| 672 | QCoreApplication::QCoreApplication(QCoreApplicationPrivate &p) | - | ||||||||||||||||||||||||
| 673 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 674 | : d_ptr(&p) | - | ||||||||||||||||||||||||
| 675 | #else | - | ||||||||||||||||||||||||
| 676 | : QObject(p, 0) | - | ||||||||||||||||||||||||
| 677 | #endif | - | ||||||||||||||||||||||||
| 678 | { | - | ||||||||||||||||||||||||
| 679 | d_func()->q_ptr = this; | - | ||||||||||||||||||||||||
| 680 | // note: it is the subclasses' job to call | - | ||||||||||||||||||||||||
| 681 | // QCoreApplicationPrivate::eventDispatcher->startingUp(); | - | ||||||||||||||||||||||||
| 682 | } | - | ||||||||||||||||||||||||
| 683 | - | |||||||||||||||||||||||||
| 684 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 685 | /*! | - | ||||||||||||||||||||||||
| 686 | Flushes the platform-specific event queues. | - | ||||||||||||||||||||||||
| 687 | - | |||||||||||||||||||||||||
| 688 | If you are doing graphical changes inside a loop that does not | - | ||||||||||||||||||||||||
| 689 | return to the event loop on asynchronous window systems like X11 | - | ||||||||||||||||||||||||
| 690 | or double buffered window systems like Quartz (\macos and iOS), and you want to | - | ||||||||||||||||||||||||
| 691 | visualize these changes immediately (e.g. Splash Screens), call | - | ||||||||||||||||||||||||
| 692 | this function. | - | ||||||||||||||||||||||||
| 693 | - | |||||||||||||||||||||||||
| 694 | \sa sendPostedEvents() | - | ||||||||||||||||||||||||
| 695 | */ | - | ||||||||||||||||||||||||
| 696 | void QCoreApplication::flush() | - | ||||||||||||||||||||||||
| 697 | { | - | ||||||||||||||||||||||||
| 698 | if (self && self->d_func()->eventDispatcher) | - | ||||||||||||||||||||||||
| 699 | self->d_func()->eventDispatcher->flush(); | - | ||||||||||||||||||||||||
| 700 | } | - | ||||||||||||||||||||||||
| 701 | #endif | - | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | /*! | - | ||||||||||||||||||||||||
| 704 | Constructs a Qt core application. Core applications are applications without | - | ||||||||||||||||||||||||
| 705 | a graphical user interface. Such applications are used at the console or as | - | ||||||||||||||||||||||||
| 706 | server processes. | - | ||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||
| 708 | The \a argc and \a argv arguments are processed by the application, | - | ||||||||||||||||||||||||
| 709 | and made available in a more convenient form by the arguments() | - | ||||||||||||||||||||||||
| 710 | function. | - | ||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||
| 712 | \warning The data referred to by \a argc and \a argv must stay valid | - | ||||||||||||||||||||||||
| 713 | for the entire lifetime of the QCoreApplication object. In addition, | - | ||||||||||||||||||||||||
| 714 | \a argc must be greater than zero and \a argv must contain at least | - | ||||||||||||||||||||||||
| 715 | one valid character string. | - | ||||||||||||||||||||||||
| 716 | */ | - | ||||||||||||||||||||||||
| 717 | QCoreApplication::QCoreApplication(int &argc, char **argv | - | ||||||||||||||||||||||||
| 718 | #ifndef Q_QDOC | - | ||||||||||||||||||||||||
| 719 | , int _internal | - | ||||||||||||||||||||||||
| 720 | #endif | - | ||||||||||||||||||||||||
| 721 | ) | - | ||||||||||||||||||||||||
| 722 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 723 | : d_ptr(new QCoreApplicationPrivate(argc, argv, _internal)) | - | ||||||||||||||||||||||||
| 724 | #else | - | ||||||||||||||||||||||||
| 725 | : QObject(*new QCoreApplicationPrivate(argc, argv, _internal)) | - | ||||||||||||||||||||||||
| 726 | #endif | - | ||||||||||||||||||||||||
| 727 | { | - | ||||||||||||||||||||||||
| 728 | d_func()->q_ptr = this; | - | ||||||||||||||||||||||||
| 729 | d_func()->init(); | - | ||||||||||||||||||||||||
| 730 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 731 | QCoreApplicationPrivate::eventDispatcher->startingUp(); | - | ||||||||||||||||||||||||
| 732 | #endif | - | ||||||||||||||||||||||||
| 733 | } | - | ||||||||||||||||||||||||
| 734 | - | |||||||||||||||||||||||||
| 735 | - | |||||||||||||||||||||||||
| 736 | void QCoreApplicationPrivate::init() | - | ||||||||||||||||||||||||
| 737 | { | - | ||||||||||||||||||||||||
| 738 | Q_Q(QCoreApplication); | - | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | initLocale(); | - | ||||||||||||||||||||||||
| 741 | - | |||||||||||||||||||||||||
| 742 | Q_ASSERT_X(!QCoreApplication::self, "QCoreApplication", "there should be only one application object"); | - | ||||||||||||||||||||||||
| 743 | QCoreApplication::self = q; | - | ||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | // Store app name (so it's still available after QCoreApplication is destroyed) | - | ||||||||||||||||||||||||
| 746 | if (!coreappdata()->applicationNameSet) | - | ||||||||||||||||||||||||
| 747 | coreappdata()->application = appName(); | - | ||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | QLoggingRegistry::instance()->init(); | - | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 752 | // Reset the lib paths, so that they will be recomputed, taking the availability of argv[0] | - | ||||||||||||||||||||||||
| 753 | // into account. If necessary, recompute right away and replay the manual changes on top of the | - | ||||||||||||||||||||||||
| 754 | // new lib paths. | - | ||||||||||||||||||||||||
| 755 | QStringList *appPaths = coreappdata()->app_libpaths.take(); | - | ||||||||||||||||||||||||
| 756 | QStringList *manualPaths = coreappdata()->manual_libpaths.take(); | - | ||||||||||||||||||||||||
| 757 | if (appPaths) { | - | ||||||||||||||||||||||||
| 758 | if (manualPaths) { | - | ||||||||||||||||||||||||
| 759 | // Replay the delta. As paths can only be prepended to the front or removed from | - | ||||||||||||||||||||||||
| 760 | // anywhere in the list, we can just linearly scan the lists and find the items that | - | ||||||||||||||||||||||||
| 761 | // have been removed. Once the original list is exhausted we know all the remaining | - | ||||||||||||||||||||||||
| 762 | // items have been added. | - | ||||||||||||||||||||||||
| 763 | QStringList newPaths(q->libraryPaths()); | - | ||||||||||||||||||||||||
| 764 | for (int i = manualPaths->length(), j = appPaths->length(); i > 0 || j > 0; qt_noop()) { | - | ||||||||||||||||||||||||
| 765 | if (--j < 0) { | - | ||||||||||||||||||||||||
| 766 | newPaths.prepend((*manualPaths)[--i]); | - | ||||||||||||||||||||||||
| 767 | } else if (--i < 0) { | - | ||||||||||||||||||||||||
| 768 | newPaths.removeAll((*appPaths)[j]); | - | ||||||||||||||||||||||||
| 769 | } else if ((*manualPaths)[i] != (*appPaths)[j]) { | - | ||||||||||||||||||||||||
| 770 | newPaths.removeAll((*appPaths)[j]); | - | ||||||||||||||||||||||||
| 771 | ++i; // try again with next item. | - | ||||||||||||||||||||||||
| 772 | } | - | ||||||||||||||||||||||||
| 773 | } | - | ||||||||||||||||||||||||
| 774 | delete manualPaths; | - | ||||||||||||||||||||||||
| 775 | coreappdata()->manual_libpaths.reset(new QStringList(newPaths)); | - | ||||||||||||||||||||||||
| 776 | } | - | ||||||||||||||||||||||||
| 777 | delete appPaths; | - | ||||||||||||||||||||||||
| 778 | } | - | ||||||||||||||||||||||||
| 779 | #endif | - | ||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||
| 781 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 782 | // use the event dispatcher created by the app programmer (if any) | - | ||||||||||||||||||||||||
| 783 | if (!eventDispatcher) | - | ||||||||||||||||||||||||
| 784 | eventDispatcher = threadData->eventDispatcher.load(); | - | ||||||||||||||||||||||||
| 785 | // otherwise we create one | - | ||||||||||||||||||||||||
| 786 | if (!eventDispatcher) | - | ||||||||||||||||||||||||
| 787 | createEventDispatcher(); | - | ||||||||||||||||||||||||
| 788 | Q_ASSERT(eventDispatcher); | - | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | if (!eventDispatcher->parent()) { | - | ||||||||||||||||||||||||
| 791 | eventDispatcher->moveToThread(threadData->thread); | - | ||||||||||||||||||||||||
| 792 | eventDispatcher->setParent(q); | - | ||||||||||||||||||||||||
| 793 | } | - | ||||||||||||||||||||||||
| 794 | - | |||||||||||||||||||||||||
| 795 | threadData->eventDispatcher = eventDispatcher; | - | ||||||||||||||||||||||||
| 796 | eventDispatcherReady(); | - | ||||||||||||||||||||||||
| 797 | #endif | - | ||||||||||||||||||||||||
| 798 | - | |||||||||||||||||||||||||
| 799 | #ifdef QT_EVAL | - | ||||||||||||||||||||||||
| 800 | extern void qt_core_eval_init(QCoreApplicationPrivate::Type); | - | ||||||||||||||||||||||||
| 801 | qt_core_eval_init(application_type); | - | ||||||||||||||||||||||||
| 802 | #endif | - | ||||||||||||||||||||||||
| 803 | - | |||||||||||||||||||||||||
| 804 | processCommandLineArguments(); | - | ||||||||||||||||||||||||
| 805 | - | |||||||||||||||||||||||||
| 806 | qt_call_pre_routines(); | - | ||||||||||||||||||||||||
| 807 | qt_startup_hook(); | - | ||||||||||||||||||||||||
| 808 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
| 809 | if (Q_UNLIKELY(qtHookData[QHooks::Startup])) | - | ||||||||||||||||||||||||
| 810 | reinterpret_cast<QHooks::StartupCallback>(qtHookData[QHooks::Startup])(); | - | ||||||||||||||||||||||||
| 811 | #endif | - | ||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||
| 813 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 814 | is_app_running = true; // No longer starting up. | - | ||||||||||||||||||||||||
| 815 | #endif | - | ||||||||||||||||||||||||
| 816 | } | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | /*! | - | ||||||||||||||||||||||||
| 819 | Destroys the QCoreApplication object. | - | ||||||||||||||||||||||||
| 820 | */ | - | ||||||||||||||||||||||||
| 821 | QCoreApplication::~QCoreApplication() | - | ||||||||||||||||||||||||
| 822 | { | - | ||||||||||||||||||||||||
| 823 | qt_call_post_routines(); | - | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | self = 0; | - | ||||||||||||||||||||||||
| 826 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 827 | QCoreApplicationPrivate::is_app_closing = true; | - | ||||||||||||||||||||||||
| 828 | QCoreApplicationPrivate::is_app_running = false; | - | ||||||||||||||||||||||||
| 829 | #endif | - | ||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | #if !defined(QT_NO_THREAD) | - | ||||||||||||||||||||||||
| 832 | // Synchronize and stop the global thread pool threads. | - | ||||||||||||||||||||||||
| 833 | QThreadPool *globalThreadPool = 0; | - | ||||||||||||||||||||||||
| 834 | QT_TRY { | - | ||||||||||||||||||||||||
| 835 | globalThreadPool = QThreadPool::globalInstance(); | - | ||||||||||||||||||||||||
| 836 | } QT_CATCH (...) { | - | ||||||||||||||||||||||||
| 837 | // swallow the exception, since destructors shouldn't throw | - | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | if (globalThreadPool) | - | ||||||||||||||||||||||||
| 840 | globalThreadPool->waitForDone(); | - | ||||||||||||||||||||||||
| 841 | #endif | - | ||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||
| 843 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 844 | d_func()->threadData->eventDispatcher = 0; | - | ||||||||||||||||||||||||
| 845 | if (QCoreApplicationPrivate::eventDispatcher) | - | ||||||||||||||||||||||||
| 846 | QCoreApplicationPrivate::eventDispatcher->closingDown(); | - | ||||||||||||||||||||||||
| 847 | QCoreApplicationPrivate::eventDispatcher = 0; | - | ||||||||||||||||||||||||
| 848 | #endif | - | ||||||||||||||||||||||||
| 849 | - | |||||||||||||||||||||||||
| 850 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 851 | coreappdata()->app_libpaths.reset(); | - | ||||||||||||||||||||||||
| 852 | coreappdata()->manual_libpaths.reset(); | - | ||||||||||||||||||||||||
| 853 | #endif | - | ||||||||||||||||||||||||
| 854 | } | - | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | /*! | - | ||||||||||||||||||||||||
| 857 | \since 5.3 | - | ||||||||||||||||||||||||
| 858 | - | |||||||||||||||||||||||||
| 859 | Allows the application to run setuid on UNIX platforms if \a allow | - | ||||||||||||||||||||||||
| 860 | is true. | - | ||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||
| 862 | If \a allow is false (the default) and Qt detects the application is | - | ||||||||||||||||||||||||
| 863 | running with an effective user id different than the real user id, | - | ||||||||||||||||||||||||
| 864 | the application will be aborted when a QCoreApplication instance is | - | ||||||||||||||||||||||||
| 865 | created. | - | ||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||
| 867 | Qt is not an appropriate solution for setuid programs due to its | - | ||||||||||||||||||||||||
| 868 | large attack surface. However some applications may be required | - | ||||||||||||||||||||||||
| 869 | to run in this manner for historical reasons. This flag will | - | ||||||||||||||||||||||||
| 870 | prevent Qt from aborting the application when this is detected, | - | ||||||||||||||||||||||||
| 871 | and must be set before a QCoreApplication instance is created. | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | \note It is strongly recommended not to enable this option since | - | ||||||||||||||||||||||||
| 874 | it introduces security risks. | - | ||||||||||||||||||||||||
| 875 | */ | - | ||||||||||||||||||||||||
| 876 | void QCoreApplication::setSetuidAllowed(bool allow) | - | ||||||||||||||||||||||||
| 877 | { | - | ||||||||||||||||||||||||
| 878 | QCoreApplicationPrivate::setuidAllowed = allow; | - | ||||||||||||||||||||||||
| 879 | } | - | ||||||||||||||||||||||||
| 880 | - | |||||||||||||||||||||||||
| 881 | /*! | - | ||||||||||||||||||||||||
| 882 | \since 5.3 | - | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | Returns true if the application is allowed to run setuid on UNIX | - | ||||||||||||||||||||||||
| 885 | platforms. | - | ||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||
| 887 | \sa QCoreApplication::setSetuidAllowed() | - | ||||||||||||||||||||||||
| 888 | */ | - | ||||||||||||||||||||||||
| 889 | bool QCoreApplication::isSetuidAllowed() | - | ||||||||||||||||||||||||
| 890 | { | - | ||||||||||||||||||||||||
| 891 | return QCoreApplicationPrivate::setuidAllowed; | - | ||||||||||||||||||||||||
| 892 | } | - | ||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||
| 894 | - | |||||||||||||||||||||||||
| 895 | /*! | - | ||||||||||||||||||||||||
| 896 | Sets the attribute \a attribute if \a on is true; | - | ||||||||||||||||||||||||
| 897 | otherwise clears the attribute. | - | ||||||||||||||||||||||||
| 898 | - | |||||||||||||||||||||||||
| 899 | \sa testAttribute() | - | ||||||||||||||||||||||||
| 900 | */ | - | ||||||||||||||||||||||||
| 901 | void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on) | - | ||||||||||||||||||||||||
| 902 | { | - | ||||||||||||||||||||||||
| 903 | if (on) | - | ||||||||||||||||||||||||
| 904 | QCoreApplicationPrivate::attribs |= 1 << attribute; | - | ||||||||||||||||||||||||
| 905 | else | - | ||||||||||||||||||||||||
| 906 | QCoreApplicationPrivate::attribs &= ~(1 << attribute); | - | ||||||||||||||||||||||||
| 907 | } | - | ||||||||||||||||||||||||
| 908 | - | |||||||||||||||||||||||||
| 909 | /*! | - | ||||||||||||||||||||||||
| 910 | Returns \c true if attribute \a attribute is set; | - | ||||||||||||||||||||||||
| 911 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 912 | - | |||||||||||||||||||||||||
| 913 | \sa setAttribute() | - | ||||||||||||||||||||||||
| 914 | */ | - | ||||||||||||||||||||||||
| 915 | bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute) | - | ||||||||||||||||||||||||
| 916 | { | - | ||||||||||||||||||||||||
| 917 | return QCoreApplicationPrivate::testAttribute(attribute); | - | ||||||||||||||||||||||||
| 918 | } | - | ||||||||||||||||||||||||
| 919 | - | |||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 922 | - | |||||||||||||||||||||||||
| 923 | /*! | - | ||||||||||||||||||||||||
| 924 | \property QCoreApplication::quitLockEnabled | - | ||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||
| 926 | \brief Whether the use of the QEventLoopLocker feature can cause the | - | ||||||||||||||||||||||||
| 927 | application to quit. | - | ||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||
| 929 | The default is \c true. | - | ||||||||||||||||||||||||
| 930 | - | |||||||||||||||||||||||||
| 931 | \sa QEventLoopLocker | - | ||||||||||||||||||||||||
| 932 | */ | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | bool QCoreApplication::isQuitLockEnabled() | - | ||||||||||||||||||||||||
| 935 | { | - | ||||||||||||||||||||||||
| 936 | return quitLockRefEnabled; | - | ||||||||||||||||||||||||
| 937 | } | - | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | static bool doNotify(QObject *, QEvent *); | - | ||||||||||||||||||||||||
| 940 | - | |||||||||||||||||||||||||
| 941 | void QCoreApplication::setQuitLockEnabled(bool enabled) | - | ||||||||||||||||||||||||
| 942 | { | - | ||||||||||||||||||||||||
| 943 | quitLockRefEnabled = enabled; | - | ||||||||||||||||||||||||
| 944 | } | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | /*! | - | ||||||||||||||||||||||||
| 947 | \internal | - | ||||||||||||||||||||||||
| 948 | \deprecated | - | ||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||
| 950 | This function is here to make it possible for Qt extensions to | - | ||||||||||||||||||||||||
| 951 | hook into event notification without subclassing QApplication | - | ||||||||||||||||||||||||
| 952 | */ | - | ||||||||||||||||||||||||
| 953 | bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 954 | { | - | ||||||||||||||||||||||||
| 955 | return notifyInternal2(receiver, event); | - | ||||||||||||||||||||||||
| 956 | } | - | ||||||||||||||||||||||||
| 957 | - | |||||||||||||||||||||||||
| 958 | /*! | - | ||||||||||||||||||||||||
| 959 | \internal | - | ||||||||||||||||||||||||
| 960 | \since 5.6 | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | This function is here to make it possible for Qt extensions to | - | ||||||||||||||||||||||||
| 963 | hook into event notification without subclassing QApplication. | - | ||||||||||||||||||||||||
| 964 | */ | - | ||||||||||||||||||||||||
| 965 | bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 966 | { | - | ||||||||||||||||||||||||
| 967 | bool selfRequired = QCoreApplicationPrivate::threadRequiresCoreApplication(); | - | ||||||||||||||||||||||||
| 968 | if (!self && selfRequired)
| 48-1767023 | ||||||||||||||||||||||||
| 969 | return false; executed 48 times by 8 tests: return false;Executed by:
| 48 | ||||||||||||||||||||||||
| 970 | - | |||||||||||||||||||||||||
| 971 | // Make it possible for Qt Script to hook into events even | - | ||||||||||||||||||||||||
| 972 | // though QApplication is subclassed... | - | ||||||||||||||||||||||||
| 973 | bool result = false; | - | ||||||||||||||||||||||||
| 974 | void *cbdata[] = { receiver, event, &result }; | - | ||||||||||||||||||||||||
| 975 | if (QInternal::activateCallbacks(QInternal::EventNotifyCallback, cbdata)) {
| 0-1768594 | ||||||||||||||||||||||||
| 976 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 977 | } | - | ||||||||||||||||||||||||
| 978 | - | |||||||||||||||||||||||||
| 979 | // Qt enforces the rule that events can only be sent to objects in | - | ||||||||||||||||||||||||
| 980 | // the current thread, so receiver->d_func()->threadData is | - | ||||||||||||||||||||||||
| 981 | // equivalent to QThreadData::current(), just without the function | - | ||||||||||||||||||||||||
| 982 | // call overhead. | - | ||||||||||||||||||||||||
| 983 | QObjectPrivate *d = receiver->d_func(); | - | ||||||||||||||||||||||||
| 984 | QThreadData *threadData = d->threadData; | - | ||||||||||||||||||||||||
| 985 | QScopedLoopLevelCounter loopLevelCounterQScopedScopeLevelCounter scopeLevelCounter(threadData); | - | ||||||||||||||||||||||||
| 986 | if (!selfRequired)
| 22367-1746227 | ||||||||||||||||||||||||
| 987 | return doNotify(receiver, event); executed 22367 times by 324 tests: return doNotify(receiver, event);Executed by:
| 22367 | ||||||||||||||||||||||||
| 988 | return self->notify(receiver, event); executed 1746227 times by 495 tests: return self->notify(receiver, event);Executed by:
| 1746227 | ||||||||||||||||||||||||
| 989 | } | - | ||||||||||||||||||||||||
| 990 | - | |||||||||||||||||||||||||
| 991 | /*! | - | ||||||||||||||||||||||||
| 992 | Sends \a event to \a receiver: \a {receiver}->event(\a event). | - | ||||||||||||||||||||||||
| 993 | Returns the value that is returned from the receiver's event | - | ||||||||||||||||||||||||
| 994 | handler. Note that this function is called for all events sent to | - | ||||||||||||||||||||||||
| 995 | any object in any thread. | - | ||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | For certain types of events (e.g. mouse and key events), | - | ||||||||||||||||||||||||
| 998 | the event will be propagated to the receiver's parent and so on up to | - | ||||||||||||||||||||||||
| 999 | the top-level object if the receiver is not interested in the event | - | ||||||||||||||||||||||||
| 1000 | (i.e., it returns \c false). | - | ||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | There are five different ways that events can be processed; | - | ||||||||||||||||||||||||
| 1003 | reimplementing this virtual function is just one of them. All five | - | ||||||||||||||||||||||||
| 1004 | approaches are listed below: | - | ||||||||||||||||||||||||
| 1005 | \list 1 | - | ||||||||||||||||||||||||
| 1006 | \li Reimplementing \l {QWidget::}{paintEvent()}, \l {QWidget::}{mousePressEvent()} and so | - | ||||||||||||||||||||||||
| 1007 | on. This is the most common, easiest, and least powerful way. | - | ||||||||||||||||||||||||
| 1008 | - | |||||||||||||||||||||||||
| 1009 | \li Reimplementing this function. This is very powerful, providing | - | ||||||||||||||||||||||||
| 1010 | complete control; but only one subclass can be active at a time. | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | \li Installing an event filter on QCoreApplication::instance(). Such | - | ||||||||||||||||||||||||
| 1013 | an event filter is able to process all events for all widgets, so | - | ||||||||||||||||||||||||
| 1014 | it's just as powerful as reimplementing notify(); furthermore, it's | - | ||||||||||||||||||||||||
| 1015 | possible to have more than one application-global event filter. | - | ||||||||||||||||||||||||
| 1016 | Global event filters even see mouse events for | - | ||||||||||||||||||||||||
| 1017 | \l{QWidget::isEnabled()}{disabled widgets}. Note that application | - | ||||||||||||||||||||||||
| 1018 | event filters are only called for objects that live in the main | - | ||||||||||||||||||||||||
| 1019 | thread. | - | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | \li Reimplementing QObject::event() (as QWidget does). If you do | - | ||||||||||||||||||||||||
| 1022 | this you get Tab key presses, and you get to see the events before | - | ||||||||||||||||||||||||
| 1023 | any widget-specific event filters. | - | ||||||||||||||||||||||||
| 1024 | - | |||||||||||||||||||||||||
| 1025 | \li Installing an event filter on the object. Such an event filter gets all | - | ||||||||||||||||||||||||
| 1026 | the events, including Tab and Shift+Tab key press events, as long as they | - | ||||||||||||||||||||||||
| 1027 | do not change the focus widget. | - | ||||||||||||||||||||||||
| 1028 | \endlist | - | ||||||||||||||||||||||||
| 1029 | - | |||||||||||||||||||||||||
| 1030 | \b{Future direction:} This function will not be called for objects that live | - | ||||||||||||||||||||||||
| 1031 | outside the main thread in Qt 6. Applications that need that functionality | - | ||||||||||||||||||||||||
| 1032 | should find other solutions for their event inspection needs in the meantime. | - | ||||||||||||||||||||||||
| 1033 | The change may be extended to the main thread, causing this function to be | - | ||||||||||||||||||||||||
| 1034 | deprecated. | - | ||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||
| 1036 | \warning If you override this function, you must ensure all threads that | - | ||||||||||||||||||||||||
| 1037 | process events stop doing so before your application object begins | - | ||||||||||||||||||||||||
| 1038 | destruction. This includes threads started by other libraries that you may be | - | ||||||||||||||||||||||||
| 1039 | using, but does not apply to Qt's own threads. | - | ||||||||||||||||||||||||
| 1040 | - | |||||||||||||||||||||||||
| 1041 | \sa QObject::event(), installNativeEventFilter() | - | ||||||||||||||||||||||||
| 1042 | */ | - | ||||||||||||||||||||||||
| 1043 | - | |||||||||||||||||||||||||
| 1044 | bool QCoreApplication::notify(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 1045 | { | - | ||||||||||||||||||||||||
| 1046 | // no events are delivered after ~QCoreApplication() has started | - | ||||||||||||||||||||||||
| 1047 | if (QCoreApplicationPrivate::is_app_closing) | - | ||||||||||||||||||||||||
| 1048 | return true; | - | ||||||||||||||||||||||||
| 1049 | return doNotify(receiver, event); | - | ||||||||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||||||||
| 1051 | - | |||||||||||||||||||||||||
| 1052 | static bool doNotify(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 1053 | { | - | ||||||||||||||||||||||||
| 1054 | if (receiver == 0) { // serious error | - | ||||||||||||||||||||||||
| 1055 | qWarning("QCoreApplication::notify: Unexpected null receiver"); | - | ||||||||||||||||||||||||
| 1056 | return true; | - | ||||||||||||||||||||||||
| 1057 | } | - | ||||||||||||||||||||||||
| 1058 | - | |||||||||||||||||||||||||
| 1059 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||||||||
| 1060 | QCoreApplicationPrivate::checkReceiverThread(receiver); | - | ||||||||||||||||||||||||
| 1061 | #endif | - | ||||||||||||||||||||||||
| 1062 | - | |||||||||||||||||||||||||
| 1063 | return receiver->isWidgetType() ? false : QCoreApplicationPrivate::notify_helper(receiver, event); | - | ||||||||||||||||||||||||
| 1064 | } | - | ||||||||||||||||||||||||
| 1065 | - | |||||||||||||||||||||||||
| 1066 | bool QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 1067 | { | - | ||||||||||||||||||||||||
| 1068 | // We can't access the application event filters outside of the main thread (race conditions) | - | ||||||||||||||||||||||||
| 1069 | Q_ASSERT(receiver->d_func()->threadData->thread == mainThread()); | - | ||||||||||||||||||||||||
| 1070 | - | |||||||||||||||||||||||||
| 1071 | if (extraData) { | - | ||||||||||||||||||||||||
| 1072 | // application event filters are only called for objects in the GUI thread | - | ||||||||||||||||||||||||
| 1073 | for (int i = 0; i < extraData->eventFilters.size(); ++i) { | - | ||||||||||||||||||||||||
| 1074 | QObject *obj = extraData->eventFilters.at(i); | - | ||||||||||||||||||||||||
| 1075 | if (!obj) | - | ||||||||||||||||||||||||
| 1076 | continue; | - | ||||||||||||||||||||||||
| 1077 | if (obj->d_func()->threadData != threadData) { | - | ||||||||||||||||||||||||
| 1078 | qWarning("QCoreApplication: Application event filter cannot be in a different thread."); | - | ||||||||||||||||||||||||
| 1079 | continue; | - | ||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||
| 1081 | if (obj->eventFilter(receiver, event)) | - | ||||||||||||||||||||||||
| 1082 | return true; | - | ||||||||||||||||||||||||
| 1083 | } | - | ||||||||||||||||||||||||
| 1084 | } | - | ||||||||||||||||||||||||
| 1085 | return false; | - | ||||||||||||||||||||||||
| 1086 | } | - | ||||||||||||||||||||||||
| 1087 | - | |||||||||||||||||||||||||
| 1088 | bool QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 1089 | { | - | ||||||||||||||||||||||||
| 1090 | if (receiver != QCoreApplication::instance() && receiver->d_func()->extraData) { | - | ||||||||||||||||||||||||
| 1091 | for (int i = 0; i < receiver->d_func()->extraData->eventFilters.size(); ++i) { | - | ||||||||||||||||||||||||
| 1092 | QObject *obj = receiver->d_func()->extraData->eventFilters.at(i); | - | ||||||||||||||||||||||||
| 1093 | if (!obj) | - | ||||||||||||||||||||||||
| 1094 | continue; | - | ||||||||||||||||||||||||
| 1095 | if (obj->d_func()->threadData != receiver->d_func()->threadData) { | - | ||||||||||||||||||||||||
| 1096 | qWarning("QCoreApplication: Object event filter cannot be in a different thread."); | - | ||||||||||||||||||||||||
| 1097 | continue; | - | ||||||||||||||||||||||||
| 1098 | } | - | ||||||||||||||||||||||||
| 1099 | if (obj->eventFilter(receiver, event)) | - | ||||||||||||||||||||||||
| 1100 | return true; | - | ||||||||||||||||||||||||
| 1101 | } | - | ||||||||||||||||||||||||
| 1102 | } | - | ||||||||||||||||||||||||
| 1103 | return false; | - | ||||||||||||||||||||||||
| 1104 | } | - | ||||||||||||||||||||||||
| 1105 | - | |||||||||||||||||||||||||
| 1106 | /*! | - | ||||||||||||||||||||||||
| 1107 | \internal | - | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | Helper function called by QCoreApplicationPrivate::notify() and qapplication.cpp | - | ||||||||||||||||||||||||
| 1110 | */ | - | ||||||||||||||||||||||||
| 1111 | bool QCoreApplicationPrivate::notify_helper(QObject *receiver, QEvent * event) | - | ||||||||||||||||||||||||
| 1112 | { | - | ||||||||||||||||||||||||
| 1113 | // send to all application event filters (only does anything in the main thread) | - | ||||||||||||||||||||||||
| 1114 | if (QCoreApplication::self | - | ||||||||||||||||||||||||
| 1115 | && receiver->d_func()->threadData->thread == mainThread() | - | ||||||||||||||||||||||||
| 1116 | && QCoreApplication::self->d_func()->sendThroughApplicationEventFilters(receiver, event)) | - | ||||||||||||||||||||||||
| 1117 | return true; | - | ||||||||||||||||||||||||
| 1118 | // send to all receiver event filters | - | ||||||||||||||||||||||||
| 1119 | if (sendThroughObjectEventFilters(receiver, event)) | - | ||||||||||||||||||||||||
| 1120 | return true; | - | ||||||||||||||||||||||||
| 1121 | // deliver the event | - | ||||||||||||||||||||||||
| 1122 | return receiver->event(event); | - | ||||||||||||||||||||||||
| 1123 | } | - | ||||||||||||||||||||||||
| 1124 | - | |||||||||||||||||||||||||
| 1125 | /*! | - | ||||||||||||||||||||||||
| 1126 | Returns \c true if an application object has not been created yet; | - | ||||||||||||||||||||||||
| 1127 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1128 | - | |||||||||||||||||||||||||
| 1129 | \sa closingDown() | - | ||||||||||||||||||||||||
| 1130 | */ | - | ||||||||||||||||||||||||
| 1131 | - | |||||||||||||||||||||||||
| 1132 | bool QCoreApplication::startingUp() | - | ||||||||||||||||||||||||
| 1133 | { | - | ||||||||||||||||||||||||
| 1134 | return !QCoreApplicationPrivate::is_app_running; | - | ||||||||||||||||||||||||
| 1135 | } | - | ||||||||||||||||||||||||
| 1136 | - | |||||||||||||||||||||||||
| 1137 | /*! | - | ||||||||||||||||||||||||
| 1138 | Returns \c true if the application objects are being destroyed; | - | ||||||||||||||||||||||||
| 1139 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||
| 1141 | \sa startingUp() | - | ||||||||||||||||||||||||
| 1142 | */ | - | ||||||||||||||||||||||||
| 1143 | - | |||||||||||||||||||||||||
| 1144 | bool QCoreApplication::closingDown() | - | ||||||||||||||||||||||||
| 1145 | { | - | ||||||||||||||||||||||||
| 1146 | return QCoreApplicationPrivate::is_app_closing; | - | ||||||||||||||||||||||||
| 1147 | } | - | ||||||||||||||||||||||||
| 1148 | - | |||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||
| 1150 | /*! | - | ||||||||||||||||||||||||
| 1151 | Processes all pending events for the calling thread according to | - | ||||||||||||||||||||||||
| 1152 | the specified \a flags until there are no more events to process. | - | ||||||||||||||||||||||||
| 1153 | - | |||||||||||||||||||||||||
| 1154 | You can call this function occasionally when your program is busy | - | ||||||||||||||||||||||||
| 1155 | performing a long operation (e.g. copying a file). | - | ||||||||||||||||||||||||
| 1156 | - | |||||||||||||||||||||||||
| 1157 | In the event that you are running a local loop which calls this function | - | ||||||||||||||||||||||||
| 1158 | continuously, without an event loop, the | - | ||||||||||||||||||||||||
| 1159 | \l{QEvent::DeferredDelete}{DeferredDelete} events will | - | ||||||||||||||||||||||||
| 1160 | not be processed. This can affect the behaviour of widgets, | - | ||||||||||||||||||||||||
| 1161 | e.g. QToolTip, that rely on \l{QEvent::DeferredDelete}{DeferredDelete} | - | ||||||||||||||||||||||||
| 1162 | events to function properly. An alternative would be to call | - | ||||||||||||||||||||||||
| 1163 | \l{QCoreApplication::sendPostedEvents()}{sendPostedEvents()} from | - | ||||||||||||||||||||||||
| 1164 | within that local loop. | - | ||||||||||||||||||||||||
| 1165 | - | |||||||||||||||||||||||||
| 1166 | Calling this function processes events only for the calling thread. | - | ||||||||||||||||||||||||
| 1167 | - | |||||||||||||||||||||||||
| 1168 | \threadsafe | - | ||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||
| 1170 | \sa exec(), QTimer, QEventLoop::processEvents(), flush(), sendPostedEvents() | - | ||||||||||||||||||||||||
| 1171 | */ | - | ||||||||||||||||||||||||
| 1172 | void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags) | - | ||||||||||||||||||||||||
| 1173 | { | - | ||||||||||||||||||||||||
| 1174 | QThreadData *data = QThreadData::current(); | - | ||||||||||||||||||||||||
| 1175 | if (!data->hasEventDispatcher()) | - | ||||||||||||||||||||||||
| 1176 | return; | - | ||||||||||||||||||||||||
| 1177 | data->eventDispatcher.load()->processEvents(flags); | - | ||||||||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||
| 1180 | /*! | - | ||||||||||||||||||||||||
| 1181 | \overload processEvents() | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | Processes pending events for the calling thread for \a maxtime | - | ||||||||||||||||||||||||
| 1184 | milliseconds or until there are no more events to process, | - | ||||||||||||||||||||||||
| 1185 | whichever is shorter. | - | ||||||||||||||||||||||||
| 1186 | - | |||||||||||||||||||||||||
| 1187 | You can call this function occasionally when your program is busy | - | ||||||||||||||||||||||||
| 1188 | doing a long operation (e.g. copying a file). | - | ||||||||||||||||||||||||
| 1189 | - | |||||||||||||||||||||||||
| 1190 | Calling this function processes events only for the calling thread. | - | ||||||||||||||||||||||||
| 1191 | - | |||||||||||||||||||||||||
| 1192 | \threadsafe | - | ||||||||||||||||||||||||
| 1193 | - | |||||||||||||||||||||||||
| 1194 | \sa exec(), QTimer, QEventLoop::processEvents() | - | ||||||||||||||||||||||||
| 1195 | */ | - | ||||||||||||||||||||||||
| 1196 | void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime) | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | // ### Qt 6: consider splitting this method into a public and a private | - | ||||||||||||||||||||||||
| 1199 | // one, so that a user-invoked processEvents can be detected | - | ||||||||||||||||||||||||
| 1200 | // and handled properly. | - | ||||||||||||||||||||||||
| 1201 | QThreadData *data = QThreadData::current(); | - | ||||||||||||||||||||||||
| 1202 | if (!data->hasEventDispatcher())
| 0-1255742 | ||||||||||||||||||||||||
| 1203 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1204 | QElapsedTimer start; | - | ||||||||||||||||||||||||
| 1205 | start.start(); | - | ||||||||||||||||||||||||
| 1206 | while (data->eventDispatcher.load()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) {
| 40298-1255473 | ||||||||||||||||||||||||
| 1207 | if (start.elapsed() > maxtime)
| 269-40029 | ||||||||||||||||||||||||
| 1208 | break; executed 269 times by 44 tests: break;Executed by:
| 269 | ||||||||||||||||||||||||
| 1209 | } executed 40029 times by 148 tests: end of blockExecuted by:
| 40029 | ||||||||||||||||||||||||
| 1210 | } executed 1255742 times by 149 tests: end of blockExecuted by:
| 1255742 | ||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||
| 1212 | /***************************************************************************** | - | ||||||||||||||||||||||||
| 1213 | Main event loop wrappers | - | ||||||||||||||||||||||||
| 1214 | *****************************************************************************/ | - | ||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | /*! | - | ||||||||||||||||||||||||
| 1217 | Enters the main event loop and waits until exit() is called. Returns | - | ||||||||||||||||||||||||
| 1218 | the value that was passed to exit() (which is 0 if exit() is called via | - | ||||||||||||||||||||||||
| 1219 | quit()). | - | ||||||||||||||||||||||||
| 1220 | - | |||||||||||||||||||||||||
| 1221 | It is necessary to call this function to start event handling. The | - | ||||||||||||||||||||||||
| 1222 | main event loop receives events from the window system and | - | ||||||||||||||||||||||||
| 1223 | dispatches these to the application widgets. | - | ||||||||||||||||||||||||
| 1224 | - | |||||||||||||||||||||||||
| 1225 | To make your application perform idle processing (by executing a | - | ||||||||||||||||||||||||
| 1226 | special function whenever there are no pending events), use a | - | ||||||||||||||||||||||||
| 1227 | QTimer with 0 timeout. More advanced idle processing schemes can | - | ||||||||||||||||||||||||
| 1228 | be achieved using processEvents(). | - | ||||||||||||||||||||||||
| 1229 | - | |||||||||||||||||||||||||
| 1230 | We recommend that you connect clean-up code to the | - | ||||||||||||||||||||||||
| 1231 | \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in | - | ||||||||||||||||||||||||
| 1232 | your application's \c{main()} function because on some platforms the | - | ||||||||||||||||||||||||
| 1233 | exec() call may not return. For example, on Windows | - | ||||||||||||||||||||||||
| 1234 | when the user logs off, the system terminates the process after Qt | - | ||||||||||||||||||||||||
| 1235 | closes all top-level windows. Hence, there is no guarantee that the | - | ||||||||||||||||||||||||
| 1236 | application will have time to exit its event loop and execute code at | - | ||||||||||||||||||||||||
| 1237 | the end of the \c{main()} function after the exec() | - | ||||||||||||||||||||||||
| 1238 | call. | - | ||||||||||||||||||||||||
| 1239 | - | |||||||||||||||||||||||||
| 1240 | \sa quit(), exit(), processEvents(), QApplication::exec() | - | ||||||||||||||||||||||||
| 1241 | */ | - | ||||||||||||||||||||||||
| 1242 | int QCoreApplication::exec() | - | ||||||||||||||||||||||||
| 1243 | { | - | ||||||||||||||||||||||||
| 1244 | if (!QCoreApplicationPrivate::checkInstance("exec")) | - | ||||||||||||||||||||||||
| 1245 | return -1; | - | ||||||||||||||||||||||||
| 1246 | - | |||||||||||||||||||||||||
| 1247 | QThreadData *threadData = self->d_func()->threadData; | - | ||||||||||||||||||||||||
| 1248 | if (threadData != QThreadData::current()) { | - | ||||||||||||||||||||||||
| 1249 | qWarning("%s::exec: Must be called from the main thread", self->metaObject()->className()); | - | ||||||||||||||||||||||||
| 1250 | return -1; | - | ||||||||||||||||||||||||
| 1251 | } | - | ||||||||||||||||||||||||
| 1252 | if (!threadData->eventLoops.isEmpty()) { | - | ||||||||||||||||||||||||
| 1253 | qWarning("QCoreApplication::exec: The event loop is already running"); | - | ||||||||||||||||||||||||
| 1254 | return -1; | - | ||||||||||||||||||||||||
| 1255 | } | - | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | threadData->quitNow = false; | - | ||||||||||||||||||||||||
| 1258 | QEventLoop eventLoop; | - | ||||||||||||||||||||||||
| 1259 | self->d_func()->in_exec = true; | - | ||||||||||||||||||||||||
| 1260 | self->d_func()->aboutToQuitEmitted = false; | - | ||||||||||||||||||||||||
| 1261 | int returnCode = eventLoop.exec(); | - | ||||||||||||||||||||||||
| 1262 | threadData->quitNow = false; | - | ||||||||||||||||||||||||
| 1263 | if (self) { | - | ||||||||||||||||||||||||
| 1264 | self->d_func()->in_exec = false; | - | ||||||||||||||||||||||||
| 1265 | if (!self->d_func()->aboutToQuitEmitted) | - | ||||||||||||||||||||||||
| 1266 | emit self->aboutToQuit(QPrivateSignal()); | - | ||||||||||||||||||||||||
| 1267 | self->d_func()->aboutToQuitEmitted = true; | - | ||||||||||||||||||||||||
| 1268 | sendPostedEvents(0, QEvent::DeferredDelete); | - | ||||||||||||||||||||||||
| 1269 | } | - | ||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||
| 1271 | return returnCode; | - | ||||||||||||||||||||||||
| 1272 | } | - | ||||||||||||||||||||||||
| 1273 | - | |||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | /*! | - | ||||||||||||||||||||||||
| 1276 | Tells the application to exit with a return code. | - | ||||||||||||||||||||||||
| 1277 | - | |||||||||||||||||||||||||
| 1278 | After this function has been called, the application leaves the | - | ||||||||||||||||||||||||
| 1279 | main event loop and returns from the call to exec(). The exec() | - | ||||||||||||||||||||||||
| 1280 | function returns \a returnCode. If the event loop is not running, | - | ||||||||||||||||||||||||
| 1281 | this function does nothing. | - | ||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||
| 1283 | By convention, a \a returnCode of 0 means success, and any non-zero | - | ||||||||||||||||||||||||
| 1284 | value indicates an error. | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | Note that unlike the C library function of the same name, this | - | ||||||||||||||||||||||||
| 1287 | function \e does return to the caller -- it is event processing that | - | ||||||||||||||||||||||||
| 1288 | stops. | - | ||||||||||||||||||||||||
| 1289 | - | |||||||||||||||||||||||||
| 1290 | \sa quit(), exec() | - | ||||||||||||||||||||||||
| 1291 | */ | - | ||||||||||||||||||||||||
| 1292 | void QCoreApplication::exit(int returnCode) | - | ||||||||||||||||||||||||
| 1293 | { | - | ||||||||||||||||||||||||
| 1294 | if (!self) | - | ||||||||||||||||||||||||
| 1295 | return; | - | ||||||||||||||||||||||||
| 1296 | QThreadData *data = self->d_func()->threadData; | - | ||||||||||||||||||||||||
| 1297 | data->quitNow = true; | - | ||||||||||||||||||||||||
| 1298 | for (int i = 0; i < data->eventLoops.size(); ++i) { | - | ||||||||||||||||||||||||
| 1299 | QEventLoop *eventLoop = data->eventLoops.at(i); | - | ||||||||||||||||||||||||
| 1300 | eventLoop->exit(returnCode); | - | ||||||||||||||||||||||||
| 1301 | } | - | ||||||||||||||||||||||||
| 1302 | #ifdef Q_OS_WINRT | - | ||||||||||||||||||||||||
| 1303 | qWarning("QCoreApplication::exit: It is not recommended to explicitly exit an application on Windows Store Apps"); | - | ||||||||||||||||||||||||
| 1304 | ComPtr<ICoreApplication> app; | - | ||||||||||||||||||||||||
| 1305 | HRESULT hr = RoGetActivationFactory(Wrappers::HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), | - | ||||||||||||||||||||||||
| 1306 | IID_PPV_ARGS(&app)); | - | ||||||||||||||||||||||||
| 1307 | RETURN_VOID_IF_FAILED("Could not acquire ICoreApplication object"); | - | ||||||||||||||||||||||||
| 1308 | ComPtr<ICoreApplicationExit> appExit; | - | ||||||||||||||||||||||||
| 1309 | - | |||||||||||||||||||||||||
| 1310 | hr = app.As(&appExit); | - | ||||||||||||||||||||||||
| 1311 | RETURN_VOID_IF_FAILED("Could not acquire ICoreApplicationExit object"); | - | ||||||||||||||||||||||||
| 1312 | hr = appExit->Exit(); | - | ||||||||||||||||||||||||
| 1313 | RETURN_VOID_IF_FAILED("Could not exit application"); | - | ||||||||||||||||||||||||
| 1314 | #endif // Q_OS_WINRT | - | ||||||||||||||||||||||||
| 1315 | } | - | ||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||
| 1317 | /***************************************************************************** | - | ||||||||||||||||||||||||
| 1318 | QCoreApplication management of posted events | - | ||||||||||||||||||||||||
| 1319 | *****************************************************************************/ | - | ||||||||||||||||||||||||
| 1320 | - | |||||||||||||||||||||||||
| 1321 | /*! | - | ||||||||||||||||||||||||
| 1322 | \fn bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event) | - | ||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||
| 1324 | Sends event \a event directly to receiver \a receiver, using the | - | ||||||||||||||||||||||||
| 1325 | notify() function. Returns the value that was returned from the | - | ||||||||||||||||||||||||
| 1326 | event handler. | - | ||||||||||||||||||||||||
| 1327 | - | |||||||||||||||||||||||||
| 1328 | The event is \e not deleted when the event has been sent. The normal | - | ||||||||||||||||||||||||
| 1329 | approach is to create the event on the stack, for example: | - | ||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||
| 1331 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 0 | - | ||||||||||||||||||||||||
| 1332 | - | |||||||||||||||||||||||||
| 1333 | \sa postEvent(), notify() | - | ||||||||||||||||||||||||
| 1334 | */ | - | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | /*! | - | ||||||||||||||||||||||||
| 1337 | \since 4.3 | - | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | Adds the event \a event, with the object \a receiver as the | - | ||||||||||||||||||||||||
| 1340 | receiver of the event, to an event queue and returns immediately. | - | ||||||||||||||||||||||||
| 1341 | - | |||||||||||||||||||||||||
| 1342 | The event must be allocated on the heap since the post event queue | - | ||||||||||||||||||||||||
| 1343 | will take ownership of the event and delete it once it has been | - | ||||||||||||||||||||||||
| 1344 | posted. It is \e {not safe} to access the event after | - | ||||||||||||||||||||||||
| 1345 | it has been posted. | - | ||||||||||||||||||||||||
| 1346 | - | |||||||||||||||||||||||||
| 1347 | When control returns to the main event loop, all events that are | - | ||||||||||||||||||||||||
| 1348 | stored in the queue will be sent using the notify() function. | - | ||||||||||||||||||||||||
| 1349 | - | |||||||||||||||||||||||||
| 1350 | Events are sorted in descending \a priority order, i.e. events | - | ||||||||||||||||||||||||
| 1351 | with a high \a priority are queued before events with a lower \a | - | ||||||||||||||||||||||||
| 1352 | priority. The \a priority can be any integer value, i.e. between | - | ||||||||||||||||||||||||
| 1353 | INT_MAX and INT_MIN, inclusive; see Qt::EventPriority for more | - | ||||||||||||||||||||||||
| 1354 | details. Events with equal \a priority will be processed in the | - | ||||||||||||||||||||||||
| 1355 | order posted. | - | ||||||||||||||||||||||||
| 1356 | - | |||||||||||||||||||||||||
| 1357 | \threadsafe | - | ||||||||||||||||||||||||
| 1358 | - | |||||||||||||||||||||||||
| 1359 | \sa sendEvent(), notify(), sendPostedEvents(), Qt::EventPriority | - | ||||||||||||||||||||||||
| 1360 | */ | - | ||||||||||||||||||||||||
| 1361 | void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) | - | ||||||||||||||||||||||||
| 1362 | { | - | ||||||||||||||||||||||||
| 1363 | if (receiver == 0) {
| 0-657414 | ||||||||||||||||||||||||
| 1364 | qWarning("QCoreApplication::postEvent: Unexpected null receiver"); | - | ||||||||||||||||||||||||
| 1365 | delete event; | - | ||||||||||||||||||||||||
| 1366 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1367 | } | - | ||||||||||||||||||||||||
| 1368 | - | |||||||||||||||||||||||||
| 1369 | QThreadData * volatile * pdata = &receiver->d_func()->threadData; | - | ||||||||||||||||||||||||
| 1370 | QThreadData *data = *pdata; | - | ||||||||||||||||||||||||
| 1371 | if (!data) {
| 0-657414 | ||||||||||||||||||||||||
| 1372 | // posting during destruction? just delete the event to prevent a leak | - | ||||||||||||||||||||||||
| 1373 | delete event; | - | ||||||||||||||||||||||||
| 1374 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1375 | } | - | ||||||||||||||||||||||||
| 1376 | - | |||||||||||||||||||||||||
| 1377 | // lock the post event mutex | - | ||||||||||||||||||||||||
| 1378 | data->postEventList.mutex.lock(); | - | ||||||||||||||||||||||||
| 1379 | - | |||||||||||||||||||||||||
| 1380 | // if object has moved to another thread, follow it | - | ||||||||||||||||||||||||
| 1381 | while (data != *pdata) {
| 0-657414 | ||||||||||||||||||||||||
| 1382 | data->postEventList.mutex.unlock(); | - | ||||||||||||||||||||||||
| 1383 | - | |||||||||||||||||||||||||
| 1384 | data = *pdata; | - | ||||||||||||||||||||||||
| 1385 | if (!data) {
| 0 | ||||||||||||||||||||||||
| 1386 | // posting during destruction? just delete the event to prevent a leak | - | ||||||||||||||||||||||||
| 1387 | delete event; | - | ||||||||||||||||||||||||
| 1388 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1389 | } | - | ||||||||||||||||||||||||
| 1390 | - | |||||||||||||||||||||||||
| 1391 | data->postEventList.mutex.lock(); | - | ||||||||||||||||||||||||
| 1392 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | QMutexUnlocker locker(&data->postEventList.mutex); | - | ||||||||||||||||||||||||
| 1395 | - | |||||||||||||||||||||||||
| 1396 | // if this is one of the compressible events, do compression | - | ||||||||||||||||||||||||
| 1397 | if (receiver->d_func()->postedEvents
| 187930-469484 | ||||||||||||||||||||||||
| 1398 | && self && self->compressEvent(event, receiver, &data->postEventList)) {
| 793-187137 | ||||||||||||||||||||||||
| 1399 | return; executed 10704 times by 106 tests: return;Executed by:
| 10704 | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) {
| 1053-635119 | ||||||||||||||||||||||||
| 1403 | // remember the current running eventloop for DeferredDelete | - | ||||||||||||||||||||||||
| 1404 | // events posted in the receiver's thread. | - | ||||||||||||||||||||||||
| 1405 | - | |||||||||||||||||||||||||
| 1406 | // Events sent by non-Qt event handlers (such as glib) may not | - | ||||||||||||||||||||||||
| 1407 | // have the scopeLevel set correctly. The scope level makes sure that | - | ||||||||||||||||||||||||
| 1408 | // code like this: | - | ||||||||||||||||||||||||
| 1409 | // foo->deleteLater(); | - | ||||||||||||||||||||||||
| 1410 | // qApp->processEvents(); // without passing QEvent::DeferredDelete | - | ||||||||||||||||||||||||
| 1411 | // will not cause "foo" to be deleted before returning to the event loop. | - | ||||||||||||||||||||||||
| 1412 | - | |||||||||||||||||||||||||
| 1413 | // If the scope level is 0 while loopLevel != 0, we are called from a | - | ||||||||||||||||||||||||
| 1414 | // non-conformant code path, and our best guess is that the scope level | - | ||||||||||||||||||||||||
| 1415 | // should be 1. (Loop level 0 is special: it means that no event loops | - | ||||||||||||||||||||||||
| 1416 | // are running.) | - | ||||||||||||||||||||||||
| 1417 | int loopLevel = data->loopLevel; | - | ||||||||||||||||||||||||
| 1418 | int scopeLevel = data->scopeLevel; | - | ||||||||||||||||||||||||
| 1419 | if (scopeLevel == 0 && loopLevel != 0)
| 2-7943 | ||||||||||||||||||||||||
| 1420 | scopeLevel = 1; executed 2 times by 1 test: scopeLevel = 1;Executed by:
| 2 | ||||||||||||||||||||||||
| 1421 | static_cast<QDeferredDeleteEvent *>(event)->level = data->loopLevel + scopeLevel; | - | ||||||||||||||||||||||||
| 1422 | } executed 10538 times by 192 tests: end of blockExecuted by:
| 10538 | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | // delete the event on exceptions to protect against memory leaks till the event is | - | ||||||||||||||||||||||||
| 1425 | // properly owned in the postEventList | - | ||||||||||||||||||||||||
| 1426 | QScopedPointer<QEvent> eventDeleter(event); | - | ||||||||||||||||||||||||
| 1427 | data->postEventList.addEvent(QPostEvent(receiver, event, priority)); | - | ||||||||||||||||||||||||
| 1428 | eventDeleter.take(); | - | ||||||||||||||||||||||||
| 1429 | event->posted = true; | - | ||||||||||||||||||||||||
| 1430 | ++receiver->d_func()->postedEvents; | - | ||||||||||||||||||||||||
| 1431 | data->canWait = false; | - | ||||||||||||||||||||||||
| 1432 | locker.unlock(); | - | ||||||||||||||||||||||||
| 1433 | - | |||||||||||||||||||||||||
| 1434 | QAbstractEventDispatcher* dispatcher = data->eventDispatcher.loadAcquire(); | - | ||||||||||||||||||||||||
| 1435 | if (dispatcher)
| 3133-643577 | ||||||||||||||||||||||||
| 1436 | dispatcher->wakeUp(); executed 643577 times by 400 tests: dispatcher->wakeUp();Executed by:
| 643577 | ||||||||||||||||||||||||
| 1437 | } executed 646710 times by 491 tests: end of blockExecuted by:
| 646710 | ||||||||||||||||||||||||
| 1438 | - | |||||||||||||||||||||||||
| 1439 | /*! | - | ||||||||||||||||||||||||
| 1440 | \internal | - | ||||||||||||||||||||||||
| 1441 | Returns \c true if \a event was compressed away (possibly deleted) and should not be added to the list. | - | ||||||||||||||||||||||||
| 1442 | */ | - | ||||||||||||||||||||||||
| 1443 | bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) | - | ||||||||||||||||||||||||
| 1444 | { | - | ||||||||||||||||||||||||
| 1445 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 1446 | Q_ASSERT(event); | - | ||||||||||||||||||||||||
| 1447 | Q_ASSERT(receiver); | - | ||||||||||||||||||||||||
| 1448 | Q_ASSERT(postedEvents); | - | ||||||||||||||||||||||||
| 1449 | - | |||||||||||||||||||||||||
| 1450 | // compress posted timers to this object. | - | ||||||||||||||||||||||||
| 1451 | if (event->type() == QEvent::Timer && receiver->d_func()->postedEvents > 0) { | - | ||||||||||||||||||||||||
| 1452 | int timerId = ((QTimerEvent *) event)->timerId(); | - | ||||||||||||||||||||||||
| 1453 | for (int i=0; i<postedEvents->size(); ++i) { | - | ||||||||||||||||||||||||
| 1454 | const QPostEvent &e = postedEvents->at(i); | - | ||||||||||||||||||||||||
| 1455 | if (e.receiver == receiver && e.event && e.event->type() == QEvent::Timer | - | ||||||||||||||||||||||||
| 1456 | && ((QTimerEvent *) e.event)->timerId() == timerId) { | - | ||||||||||||||||||||||||
| 1457 | delete event; | - | ||||||||||||||||||||||||
| 1458 | return true; | - | ||||||||||||||||||||||||
| 1459 | } | - | ||||||||||||||||||||||||
| 1460 | } | - | ||||||||||||||||||||||||
| 1461 | } else | - | ||||||||||||||||||||||||
| 1462 | #endif | - | ||||||||||||||||||||||||
| 1463 | if ((event->type() == QEvent::DeferredDelete | - | ||||||||||||||||||||||||
| 1464 | || event->type() == QEvent::Quit) | - | ||||||||||||||||||||||||
| 1465 | && receiver->d_func()->postedEvents > 0) { | - | ||||||||||||||||||||||||
| 1466 | for (int i = 0; i < postedEvents->size(); ++i) { | - | ||||||||||||||||||||||||
| 1467 | const QPostEvent &cur = postedEvents->at(i); | - | ||||||||||||||||||||||||
| 1468 | if (cur.receiver != receiver | - | ||||||||||||||||||||||||
| 1469 | || cur.event == 0 | - | ||||||||||||||||||||||||
| 1470 | || cur.event->type() != event->type()) | - | ||||||||||||||||||||||||
| 1471 | continue; | - | ||||||||||||||||||||||||
| 1472 | // found an event for this receiver | - | ||||||||||||||||||||||||
| 1473 | delete event; | - | ||||||||||||||||||||||||
| 1474 | return true; | - | ||||||||||||||||||||||||
| 1475 | } | - | ||||||||||||||||||||||||
| 1476 | } | - | ||||||||||||||||||||||||
| 1477 | return false; | - | ||||||||||||||||||||||||
| 1478 | } | - | ||||||||||||||||||||||||
| 1479 | - | |||||||||||||||||||||||||
| 1480 | /*! | - | ||||||||||||||||||||||||
| 1481 | Immediately dispatches all events which have been previously queued | - | ||||||||||||||||||||||||
| 1482 | with QCoreApplication::postEvent() and which are for the object \a receiver | - | ||||||||||||||||||||||||
| 1483 | and have the event type \a event_type. | - | ||||||||||||||||||||||||
| 1484 | - | |||||||||||||||||||||||||
| 1485 | Events from the window system are \e not dispatched by this | - | ||||||||||||||||||||||||
| 1486 | function, but by processEvents(). | - | ||||||||||||||||||||||||
| 1487 | - | |||||||||||||||||||||||||
| 1488 | If \a receiver is null, the events of \a event_type are sent for all | - | ||||||||||||||||||||||||
| 1489 | objects. If \a event_type is 0, all the events are sent for \a receiver. | - | ||||||||||||||||||||||||
| 1490 | - | |||||||||||||||||||||||||
| 1491 | \note This method must be called from the thread in which its QObject | - | ||||||||||||||||||||||||
| 1492 | parameter, \a receiver, lives. | - | ||||||||||||||||||||||||
| 1493 | - | |||||||||||||||||||||||||
| 1494 | \sa flush(), postEvent() | - | ||||||||||||||||||||||||
| 1495 | */ | - | ||||||||||||||||||||||||
| 1496 | void QCoreApplication::sendPostedEvents(QObject *receiver, int event_type) | - | ||||||||||||||||||||||||
| 1497 | { | - | ||||||||||||||||||||||||
| 1498 | // ### Qt 6: consider splitting this method into a public and a private | - | ||||||||||||||||||||||||
| 1499 | // one, so that a user-invoked sendPostedEvents can be detected | - | ||||||||||||||||||||||||
| 1500 | // and handled properly. | - | ||||||||||||||||||||||||
| 1501 | QThreadData *data = QThreadData::current(); | - | ||||||||||||||||||||||||
| 1502 | - | |||||||||||||||||||||||||
| 1503 | QCoreApplicationPrivate::sendPostedEvents(receiver, event_type, data); | - | ||||||||||||||||||||||||
| 1504 | } executed 1066841 times by 738 tests: end of blockExecuted by:
| 1066841 | ||||||||||||||||||||||||
| 1505 | - | |||||||||||||||||||||||||
| 1506 | void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type, | - | ||||||||||||||||||||||||
| 1507 | QThreadData *data) | - | ||||||||||||||||||||||||
| 1508 | { | - | ||||||||||||||||||||||||
| 1509 | if (event_type == -1) {
| 0-1066841 | ||||||||||||||||||||||||
| 1510 | // we were called by an obsolete event dispatcher. | - | ||||||||||||||||||||||||
| 1511 | event_type = 0; | - | ||||||||||||||||||||||||
| 1512 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1513 | - | |||||||||||||||||||||||||
| 1514 | if (receiver && receiver->d_func()->threadData != data) {
| 0-1065030 | ||||||||||||||||||||||||
| 1515 | qWarning("QCoreApplication::sendPostedEvents: Cannot send " | - | ||||||||||||||||||||||||
| 1516 | "posted events for objects in another thread"); | - | ||||||||||||||||||||||||
| 1517 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1518 | } | - | ||||||||||||||||||||||||
| 1519 | - | |||||||||||||||||||||||||
| 1520 | ++data->postEventList.recursion; | - | ||||||||||||||||||||||||
| 1521 | - | |||||||||||||||||||||||||
| 1522 | QMutexLocker locker(&data->postEventList.mutex); | - | ||||||||||||||||||||||||
| 1523 | - | |||||||||||||||||||||||||
| 1524 | // by default, we assume that the event dispatcher can go to sleep after | - | ||||||||||||||||||||||||
| 1525 | // processing all events. if any new events are posted while we send | - | ||||||||||||||||||||||||
| 1526 | // events, canWait will be set to false. | - | ||||||||||||||||||||||||
| 1527 | data->canWait = (data->postEventList.size() == 0); | - | ||||||||||||||||||||||||
| 1528 | - | |||||||||||||||||||||||||
| 1529 | if (data->postEventList.size() == 0 || (receiver && !receiver->d_func()->postedEvents)) {
| 52-685786 | ||||||||||||||||||||||||
| 1530 | --data->postEventList.recursion; | - | ||||||||||||||||||||||||
| 1531 | return; executed 685838 times by 708 tests: return;Executed by:
| 685838 | ||||||||||||||||||||||||
| 1532 | } | - | ||||||||||||||||||||||||
| 1533 | - | |||||||||||||||||||||||||
| 1534 | data->canWait = true; | - | ||||||||||||||||||||||||
| 1535 | - | |||||||||||||||||||||||||
| 1536 | // okay. here is the tricky loop. be careful about optimizing | - | ||||||||||||||||||||||||
| 1537 | // this, it looks the way it does for good reasons. | - | ||||||||||||||||||||||||
| 1538 | int startOffset = data->postEventList.startOffset; | - | ||||||||||||||||||||||||
| 1539 | int &i = (!event_type && !receiver) ? data->postEventList.startOffset : startOffset;
| 33-376528 | ||||||||||||||||||||||||
| 1540 | data->postEventList.insertionOffset = data->postEventList.size(); | - | ||||||||||||||||||||||||
| 1541 | - | |||||||||||||||||||||||||
| 1542 | // Exception-safe cleaning up without the need for a try/catch block | - | ||||||||||||||||||||||||
| 1543 | struct CleanUp { | - | ||||||||||||||||||||||||
| 1544 | QObject *receiver; | - | ||||||||||||||||||||||||
| 1545 | int event_type; | - | ||||||||||||||||||||||||
| 1546 | QThreadData *data; | - | ||||||||||||||||||||||||
| 1547 | bool exceptionCaught; | - | ||||||||||||||||||||||||
| 1548 | - | |||||||||||||||||||||||||
| 1549 | inline CleanUp(QObject *receiver, int event_type, QThreadData *data) : | - | ||||||||||||||||||||||||
| 1550 | receiver(receiver), event_type(event_type), data(data), exceptionCaught(true) | - | ||||||||||||||||||||||||
| 1551 | {} | - | ||||||||||||||||||||||||
| 1552 | inline ~CleanUp() | - | ||||||||||||||||||||||||
| 1553 | { | - | ||||||||||||||||||||||||
| 1554 | if (exceptionCaught) { | - | ||||||||||||||||||||||||
| 1555 | // since we were interrupted, we need another pass to make sure we clean everything up | - | ||||||||||||||||||||||||
| 1556 | data->canWait = false; | - | ||||||||||||||||||||||||
| 1557 | } | - | ||||||||||||||||||||||||
| 1558 | - | |||||||||||||||||||||||||
| 1559 | --data->postEventList.recursion; | - | ||||||||||||||||||||||||
| 1560 | if (!data->postEventList.recursion && !data->canWait && data->hasEventDispatcher()) | - | ||||||||||||||||||||||||
| 1561 | data->eventDispatcher.load()->wakeUp(); | - | ||||||||||||||||||||||||
| 1562 | - | |||||||||||||||||||||||||
| 1563 | // clear the global list, i.e. remove everything that was | - | ||||||||||||||||||||||||
| 1564 | // delivered. | - | ||||||||||||||||||||||||
| 1565 | if (!event_type && !receiver && data->postEventList.startOffset >= 0) { | - | ||||||||||||||||||||||||
| 1566 | const QPostEventList::iterator it = data->postEventList.begin(); | - | ||||||||||||||||||||||||
| 1567 | data->postEventList.erase(it, it + data->postEventList.startOffset); | - | ||||||||||||||||||||||||
| 1568 | data->postEventList.insertionOffset -= data->postEventList.startOffset; | - | ||||||||||||||||||||||||
| 1569 | Q_ASSERT(data->postEventList.insertionOffset >= 0); | - | ||||||||||||||||||||||||
| 1570 | data->postEventList.startOffset = 0; | - | ||||||||||||||||||||||||
| 1571 | } | - | ||||||||||||||||||||||||
| 1572 | } | - | ||||||||||||||||||||||||
| 1573 | }; | - | ||||||||||||||||||||||||
| 1574 | CleanUp cleanup(receiver, event_type, data); | - | ||||||||||||||||||||||||
| 1575 | - | |||||||||||||||||||||||||
| 1576 | while (i < data->postEventList.size()) {
| 352105-666141 | ||||||||||||||||||||||||
| 1577 | // avoid live-lock | - | ||||||||||||||||||||||||
| 1578 | if (i >= data->postEventList.insertionOffset)
| 28898-637243 | ||||||||||||||||||||||||
| 1579 | break; executed 28898 times by 204 tests: break;Executed by:
| 28898 | ||||||||||||||||||||||||
| 1580 | - | |||||||||||||||||||||||||
| 1581 | const QPostEvent &pe = data->postEventList.at(i); | - | ||||||||||||||||||||||||
| 1582 | ++i; | - | ||||||||||||||||||||||||
| 1583 | - | |||||||||||||||||||||||||
| 1584 | if (!pe.event)
| 45969-591274 | ||||||||||||||||||||||||
| 1585 | continue; executed 45969 times by 131 tests: continue;Executed by:
| 45969 | ||||||||||||||||||||||||
| 1586 | if ((receiver && receiver != pe.receiver) || (event_type && event_type != pe.event->type())) {
| 2567-562574 | ||||||||||||||||||||||||
| 1587 | data->canWait = false; | - | ||||||||||||||||||||||||
| 1588 | continue; executed 35405 times by 53 tests: continue;Executed by:
| 35405 | ||||||||||||||||||||||||
| 1589 | } | - | ||||||||||||||||||||||||
| 1590 | - | |||||||||||||||||||||||||
| 1591 | if (pe.event->type() == QEvent::DeferredDelete) {
| 5745-550124 | ||||||||||||||||||||||||
| 1592 | // DeferredDelete events are sent either | - | ||||||||||||||||||||||||
| 1593 | // 1) when the event loop that posted the event has returned; or | - | ||||||||||||||||||||||||
| 1594 | // 2) if explicitly requested (with QEvent::DeferredDelete) for | - | ||||||||||||||||||||||||
| 1595 | // events posted by the current event loop; or | - | ||||||||||||||||||||||||
| 1596 | // 3) if the event was posted before the outermost event loop. | - | ||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||
| 1598 | int loopLeveleventLevel = static_cast<QDeferredDeleteEvent *>(pe.event)->loopLevel(); | - | ||||||||||||||||||||||||
| 1599 | int loopLevel = data->loopLevel + data->scopeLevel; | - | ||||||||||||||||||||||||
| 1600 | const bool allowDeferredDelete = | - | ||||||||||||||||||||||||
| 1601 | (loopLeveleventLevel > data->loopLevel
| 2239-3506 | ||||||||||||||||||||||||
| 1602 | || (!loopLeveleventLevel && data->loopLevel > 0)
| 132-3374 | ||||||||||||||||||||||||
| 1603 | || (event_type == QEvent::DeferredDelete
| 808-1491 | ||||||||||||||||||||||||
| 1604 | && loopLeveleventLevel == data->loopLevel));
| 1-807 | ||||||||||||||||||||||||
| 1605 | if (!allowDeferredDelete) {
| 1492-4253 | ||||||||||||||||||||||||
| 1606 | // cannot send deferred delete | - | ||||||||||||||||||||||||
| 1607 | if (!event_type && !receiver) {
| 0-1491 | ||||||||||||||||||||||||
| 1608 | // we must copy it first; we want to re-post the event | - | ||||||||||||||||||||||||
| 1609 | // with the event pointer intact, but we can't delay | - | ||||||||||||||||||||||||
| 1610 | // nulling the event ptr until after re-posting, as | - | ||||||||||||||||||||||||
| 1611 | // addEvent may invalidate pe. | - | ||||||||||||||||||||||||
| 1612 | QPostEvent pe_copy = pe; | - | ||||||||||||||||||||||||
| 1613 | - | |||||||||||||||||||||||||
| 1614 | // null out the event so if sendPostedEvents recurses, it | - | ||||||||||||||||||||||||
| 1615 | // will ignore this one, as it's been re-posted. | - | ||||||||||||||||||||||||
| 1616 | const_cast<QPostEvent &>(pe).event = 0; | - | ||||||||||||||||||||||||
| 1617 | - | |||||||||||||||||||||||||
| 1618 | // re-post the copied event so it isn't lost | - | ||||||||||||||||||||||||
| 1619 | data->postEventList.addEvent(pe_copy); | - | ||||||||||||||||||||||||
| 1620 | } executed 1491 times by 34 tests: end of blockExecuted by:
| 1491 | ||||||||||||||||||||||||
| 1621 | continue; executed 1492 times by 34 tests: continue;Executed by:
| 1492 | ||||||||||||||||||||||||
| 1622 | } | - | ||||||||||||||||||||||||
| 1623 | } executed 4253 times by 172 tests: end of blockExecuted by:
| 4253 | ||||||||||||||||||||||||
| 1624 | - | |||||||||||||||||||||||||
| 1625 | // first, we diddle the event so that we can deliver | - | ||||||||||||||||||||||||
| 1626 | // it, and that no one will try to touch it later. | - | ||||||||||||||||||||||||
| 1627 | pe.event->posted = false; | - | ||||||||||||||||||||||||
| 1628 | QEvent *e = pe.event; | - | ||||||||||||||||||||||||
| 1629 | QObject * r = pe.receiver; | - | ||||||||||||||||||||||||
| 1630 | - | |||||||||||||||||||||||||
| 1631 | --r->d_func()->postedEvents; | - | ||||||||||||||||||||||||
| 1632 | Q_ASSERT(r->d_func()->postedEvents >= 0); | - | ||||||||||||||||||||||||
| 1633 | - | |||||||||||||||||||||||||
| 1634 | // next, update the data structure so that we're ready | - | ||||||||||||||||||||||||
| 1635 | // for the next event. | - | ||||||||||||||||||||||||
| 1636 | const_cast<QPostEvent &>(pe).event = 0; | - | ||||||||||||||||||||||||
| 1637 | - | |||||||||||||||||||||||||
| 1638 | struct MutexUnlocker | - | ||||||||||||||||||||||||
| 1639 | { | - | ||||||||||||||||||||||||
| 1640 | QMutexLocker &m; | - | ||||||||||||||||||||||||
| 1641 | MutexUnlocker(QMutexLocker &m) : m(m) { m.unlock(); } | - | ||||||||||||||||||||||||
| 1642 | ~MutexUnlocker() { m.relock(); } | - | ||||||||||||||||||||||||
| 1643 | }; | - | ||||||||||||||||||||||||
| 1644 | MutexUnlocker unlocker(locker); | - | ||||||||||||||||||||||||
| 1645 | - | |||||||||||||||||||||||||
| 1646 | QScopedPointer<QEvent> event_deleter(e); // will delete the event (with the mutex unlocked) | - | ||||||||||||||||||||||||
| 1647 | - | |||||||||||||||||||||||||
| 1648 | // after all that work, it's time to deliver the event. | - | ||||||||||||||||||||||||
| 1649 | QCoreApplication::sendEvent(r, e); | - | ||||||||||||||||||||||||
| 1650 | - | |||||||||||||||||||||||||
| 1651 | // careful when adding anything below this point - the | - | ||||||||||||||||||||||||
| 1652 | // sendEvent() call might invalidate any invariants this | - | ||||||||||||||||||||||||
| 1653 | // function depends on. | - | ||||||||||||||||||||||||
| 1654 | } executed 554376 times by 350 tests: end of blockExecuted by:
| 554376 | ||||||||||||||||||||||||
| 1655 | - | |||||||||||||||||||||||||
| 1656 | cleanup.exceptionCaught = false; | - | ||||||||||||||||||||||||
| 1657 | } executed 381003 times by 353 tests: end of blockExecuted by:
| 381003 | ||||||||||||||||||||||||
| 1658 | - | |||||||||||||||||||||||||
| 1659 | /*! | - | ||||||||||||||||||||||||
| 1660 | \since 4.3 | - | ||||||||||||||||||||||||
| 1661 | - | |||||||||||||||||||||||||
| 1662 | Removes all events of the given \a eventType that were posted | - | ||||||||||||||||||||||||
| 1663 | using postEvent() for \a receiver. | - | ||||||||||||||||||||||||
| 1664 | - | |||||||||||||||||||||||||
| 1665 | The events are \e not dispatched, instead they are removed from | - | ||||||||||||||||||||||||
| 1666 | the queue. You should never need to call this function. If you do | - | ||||||||||||||||||||||||
| 1667 | call it, be aware that killing events may cause \a receiver to | - | ||||||||||||||||||||||||
| 1668 | break one or more invariants. | - | ||||||||||||||||||||||||
| 1669 | - | |||||||||||||||||||||||||
| 1670 | If \a receiver is null, the events of \a eventType are removed for | - | ||||||||||||||||||||||||
| 1671 | all objects. If \a eventType is 0, all the events are removed for | - | ||||||||||||||||||||||||
| 1672 | \a receiver. You should never call this function with \a eventType | - | ||||||||||||||||||||||||
| 1673 | of 0. If you do call it in this way, be aware that killing events | - | ||||||||||||||||||||||||
| 1674 | may cause \a receiver to break one or more invariants. | - | ||||||||||||||||||||||||
| 1675 | - | |||||||||||||||||||||||||
| 1676 | \threadsafe | - | ||||||||||||||||||||||||
| 1677 | */ | - | ||||||||||||||||||||||||
| 1678 | - | |||||||||||||||||||||||||
| 1679 | void QCoreApplication::removePostedEvents(QObject *receiver, int eventType) | - | ||||||||||||||||||||||||
| 1680 | { | - | ||||||||||||||||||||||||
| 1681 | QThreadData *data = receiver ? receiver->d_func()->threadData : QThreadData::current(); | - | ||||||||||||||||||||||||
| 1682 | QMutexLocker locker(&data->postEventList.mutex); | - | ||||||||||||||||||||||||
| 1683 | - | |||||||||||||||||||||||||
| 1684 | // the QObject destructor calls this function directly. this can | - | ||||||||||||||||||||||||
| 1685 | // happen while the event loop is in the middle of posting events, | - | ||||||||||||||||||||||||
| 1686 | // and when we get here, we may not have any more posted events | - | ||||||||||||||||||||||||
| 1687 | // for this object. | - | ||||||||||||||||||||||||
| 1688 | if (receiver && !receiver->d_func()->postedEvents) | - | ||||||||||||||||||||||||
| 1689 | return; | - | ||||||||||||||||||||||||
| 1690 | - | |||||||||||||||||||||||||
| 1691 | //we will collect all the posted events for the QObject | - | ||||||||||||||||||||||||
| 1692 | //and we'll delete after the mutex was unlocked | - | ||||||||||||||||||||||||
| 1693 | QVarLengthArray<QEvent*> events; | - | ||||||||||||||||||||||||
| 1694 | int n = data->postEventList.size(); | - | ||||||||||||||||||||||||
| 1695 | int j = 0; | - | ||||||||||||||||||||||||
| 1696 | - | |||||||||||||||||||||||||
| 1697 | for (int i = 0; i < n; ++i) { | - | ||||||||||||||||||||||||
| 1698 | const QPostEvent &pe = data->postEventList.at(i); | - | ||||||||||||||||||||||||
| 1699 | - | |||||||||||||||||||||||||
| 1700 | if ((!receiver || pe.receiver == receiver) | - | ||||||||||||||||||||||||
| 1701 | && (pe.event && (eventType == 0 || pe.event->type() == eventType))) { | - | ||||||||||||||||||||||||
| 1702 | --pe.receiver->d_func()->postedEvents; | - | ||||||||||||||||||||||||
| 1703 | pe.event->posted = false; | - | ||||||||||||||||||||||||
| 1704 | events.append(pe.event); | - | ||||||||||||||||||||||||
| 1705 | const_cast<QPostEvent &>(pe).event = 0; | - | ||||||||||||||||||||||||
| 1706 | } else if (!data->postEventList.recursion) { | - | ||||||||||||||||||||||||
| 1707 | if (i != j) | - | ||||||||||||||||||||||||
| 1708 | qSwap(data->postEventList[i], data->postEventList[j]); | - | ||||||||||||||||||||||||
| 1709 | ++j; | - | ||||||||||||||||||||||||
| 1710 | } | - | ||||||||||||||||||||||||
| 1711 | } | - | ||||||||||||||||||||||||
| 1712 | - | |||||||||||||||||||||||||
| 1713 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
| 1714 | if (receiver && eventType == 0) { | - | ||||||||||||||||||||||||
| 1715 | Q_ASSERT(!receiver->d_func()->postedEvents); | - | ||||||||||||||||||||||||
| 1716 | } | - | ||||||||||||||||||||||||
| 1717 | #endif | - | ||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||
| 1719 | if (!data->postEventList.recursion) { | - | ||||||||||||||||||||||||
| 1720 | // truncate list | - | ||||||||||||||||||||||||
| 1721 | data->postEventList.erase(data->postEventList.begin() + j, data->postEventList.end()); | - | ||||||||||||||||||||||||
| 1722 | } | - | ||||||||||||||||||||||||
| 1723 | - | |||||||||||||||||||||||||
| 1724 | locker.unlock(); | - | ||||||||||||||||||||||||
| 1725 | for (int i = 0; i < events.count(); ++i) { | - | ||||||||||||||||||||||||
| 1726 | delete events[i]; | - | ||||||||||||||||||||||||
| 1727 | } | - | ||||||||||||||||||||||||
| 1728 | } | - | ||||||||||||||||||||||||
| 1729 | - | |||||||||||||||||||||||||
| 1730 | /*! | - | ||||||||||||||||||||||||
| 1731 | Removes \a event from the queue of posted events, and emits a | - | ||||||||||||||||||||||||
| 1732 | warning message if appropriate. | - | ||||||||||||||||||||||||
| 1733 | - | |||||||||||||||||||||||||
| 1734 | \warning This function can be \e really slow. Avoid using it, if | - | ||||||||||||||||||||||||
| 1735 | possible. | - | ||||||||||||||||||||||||
| 1736 | - | |||||||||||||||||||||||||
| 1737 | \threadsafe | - | ||||||||||||||||||||||||
| 1738 | */ | - | ||||||||||||||||||||||||
| 1739 | - | |||||||||||||||||||||||||
| 1740 | void QCoreApplicationPrivate::removePostedEvent(QEvent * event) | - | ||||||||||||||||||||||||
| 1741 | { | - | ||||||||||||||||||||||||
| 1742 | if (!event || !event->posted) | - | ||||||||||||||||||||||||
| 1743 | return; | - | ||||||||||||||||||||||||
| 1744 | - | |||||||||||||||||||||||||
| 1745 | QThreadData *data = QThreadData::current(); | - | ||||||||||||||||||||||||
| 1746 | - | |||||||||||||||||||||||||
| 1747 | QMutexLocker locker(&data->postEventList.mutex); | - | ||||||||||||||||||||||||
| 1748 | - | |||||||||||||||||||||||||
| 1749 | if (data->postEventList.size() == 0) { | - | ||||||||||||||||||||||||
| 1750 | #if defined(QT_DEBUG) | - | ||||||||||||||||||||||||
| 1751 | qDebug("QCoreApplication::removePostedEvent: Internal error: %p %d is posted", | - | ||||||||||||||||||||||||
| 1752 | (void*)event, event->type()); | - | ||||||||||||||||||||||||
| 1753 | return; | - | ||||||||||||||||||||||||
| 1754 | #endif | - | ||||||||||||||||||||||||
| 1755 | } | - | ||||||||||||||||||||||||
| 1756 | - | |||||||||||||||||||||||||
| 1757 | for (int i = 0; i < data->postEventList.size(); ++i) { | - | ||||||||||||||||||||||||
| 1758 | const QPostEvent & pe = data->postEventList.at(i); | - | ||||||||||||||||||||||||
| 1759 | if (pe.event == event) { | - | ||||||||||||||||||||||||
| 1760 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||||||||
| 1761 | qWarning("QCoreApplication::removePostedEvent: Event of type %d deleted while posted to %s %s", | - | ||||||||||||||||||||||||
| 1762 | event->type(), | - | ||||||||||||||||||||||||
| 1763 | pe.receiver->metaObject()->className(), | - | ||||||||||||||||||||||||
| 1764 | pe.receiver->objectName().toLocal8Bit().data()); | - | ||||||||||||||||||||||||
| 1765 | #endif | - | ||||||||||||||||||||||||
| 1766 | --pe.receiver->d_func()->postedEvents; | - | ||||||||||||||||||||||||
| 1767 | pe.event->posted = false; | - | ||||||||||||||||||||||||
| 1768 | delete pe.event; | - | ||||||||||||||||||||||||
| 1769 | const_cast<QPostEvent &>(pe).event = 0; | - | ||||||||||||||||||||||||
| 1770 | return; | - | ||||||||||||||||||||||||
| 1771 | } | - | ||||||||||||||||||||||||
| 1772 | } | - | ||||||||||||||||||||||||
| 1773 | } | - | ||||||||||||||||||||||||
| 1774 | - | |||||||||||||||||||||||||
| 1775 | /*!\reimp | - | ||||||||||||||||||||||||
| 1776 | - | |||||||||||||||||||||||||
| 1777 | */ | - | ||||||||||||||||||||||||
| 1778 | bool QCoreApplication::event(QEvent *e) | - | ||||||||||||||||||||||||
| 1779 | { | - | ||||||||||||||||||||||||
| 1780 | if (e->type() == QEvent::Quit) { | - | ||||||||||||||||||||||||
| 1781 | quit(); | - | ||||||||||||||||||||||||
| 1782 | return true; | - | ||||||||||||||||||||||||
| 1783 | } | - | ||||||||||||||||||||||||
| 1784 | return QObject::event(e); | - | ||||||||||||||||||||||||
| 1785 | } | - | ||||||||||||||||||||||||
| 1786 | - | |||||||||||||||||||||||||
| 1787 | /*! \enum QCoreApplication::Encoding | - | ||||||||||||||||||||||||
| 1788 | \obsolete | - | ||||||||||||||||||||||||
| 1789 | - | |||||||||||||||||||||||||
| 1790 | This enum type used to define the 8-bit encoding of character string | - | ||||||||||||||||||||||||
| 1791 | arguments to translate(). This enum is now obsolete and UTF-8 will be | - | ||||||||||||||||||||||||
| 1792 | used in all cases. | - | ||||||||||||||||||||||||
| 1793 | - | |||||||||||||||||||||||||
| 1794 | \value UnicodeUTF8 UTF-8. | - | ||||||||||||||||||||||||
| 1795 | \omitvalue Latin1 | - | ||||||||||||||||||||||||
| 1796 | \omitvalue DefaultCodec UTF-8. | - | ||||||||||||||||||||||||
| 1797 | \omitvalue CodecForTr | - | ||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||
| 1799 | \sa QObject::tr(), QString::fromUtf8() | - | ||||||||||||||||||||||||
| 1800 | */ | - | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | void QCoreApplicationPrivate::ref() | - | ||||||||||||||||||||||||
| 1803 | { | - | ||||||||||||||||||||||||
| 1804 | quitLockRef.ref(); | - | ||||||||||||||||||||||||
| 1805 | } | - | ||||||||||||||||||||||||
| 1806 | - | |||||||||||||||||||||||||
| 1807 | void QCoreApplicationPrivate::deref() | - | ||||||||||||||||||||||||
| 1808 | { | - | ||||||||||||||||||||||||
| 1809 | if (!quitLockRef.deref()) | - | ||||||||||||||||||||||||
| 1810 | maybeQuit(); | - | ||||||||||||||||||||||||
| 1811 | } | - | ||||||||||||||||||||||||
| 1812 | - | |||||||||||||||||||||||||
| 1813 | void QCoreApplicationPrivate::maybeQuit() | - | ||||||||||||||||||||||||
| 1814 | { | - | ||||||||||||||||||||||||
| 1815 | if (quitLockRef.load() == 0 && in_exec && quitLockRefEnabled && shouldQuit()) | - | ||||||||||||||||||||||||
| 1816 | QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::Quit)); | - | ||||||||||||||||||||||||
| 1817 | } | - | ||||||||||||||||||||||||
| 1818 | - | |||||||||||||||||||||||||
| 1819 | /*! | - | ||||||||||||||||||||||||
| 1820 | Tells the application to exit with return code 0 (success). | - | ||||||||||||||||||||||||
| 1821 | Equivalent to calling QCoreApplication::exit(0). | - | ||||||||||||||||||||||||
| 1822 | - | |||||||||||||||||||||||||
| 1823 | It's common to connect the QGuiApplication::lastWindowClosed() signal | - | ||||||||||||||||||||||||
| 1824 | to quit(), and you also often connect e.g. QAbstractButton::clicked() or | - | ||||||||||||||||||||||||
| 1825 | signals in QAction, QMenu, or QMenuBar to it. | - | ||||||||||||||||||||||||
| 1826 | - | |||||||||||||||||||||||||
| 1827 | Example: | - | ||||||||||||||||||||||||
| 1828 | - | |||||||||||||||||||||||||
| 1829 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 1 | - | ||||||||||||||||||||||||
| 1830 | - | |||||||||||||||||||||||||
| 1831 | \sa exit(), aboutToQuit(), QGuiApplication::lastWindowClosed() | - | ||||||||||||||||||||||||
| 1832 | */ | - | ||||||||||||||||||||||||
| 1833 | - | |||||||||||||||||||||||||
| 1834 | void QCoreApplication::quit() | - | ||||||||||||||||||||||||
| 1835 | { | - | ||||||||||||||||||||||||
| 1836 | exit(0); | - | ||||||||||||||||||||||||
| 1837 | } | - | ||||||||||||||||||||||||
| 1838 | - | |||||||||||||||||||||||||
| 1839 | /*! | - | ||||||||||||||||||||||||
| 1840 | \fn void QCoreApplication::aboutToQuit() | - | ||||||||||||||||||||||||
| 1841 | - | |||||||||||||||||||||||||
| 1842 | This signal is emitted when the application is about to quit the | - | ||||||||||||||||||||||||
| 1843 | main event loop, e.g. when the event loop level drops to zero. | - | ||||||||||||||||||||||||
| 1844 | This may happen either after a call to quit() from inside the | - | ||||||||||||||||||||||||
| 1845 | application or when the user shuts down the entire desktop session. | - | ||||||||||||||||||||||||
| 1846 | - | |||||||||||||||||||||||||
| 1847 | The signal is particularly useful if your application has to do some | - | ||||||||||||||||||||||||
| 1848 | last-second cleanup. Note that no user interaction is possible in | - | ||||||||||||||||||||||||
| 1849 | this state. | - | ||||||||||||||||||||||||
| 1850 | - | |||||||||||||||||||||||||
| 1851 | \sa quit() | - | ||||||||||||||||||||||||
| 1852 | */ | - | ||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||
| 1854 | #endif // QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1855 | - | |||||||||||||||||||||||||
| 1856 | #ifndef QT_NO_TRANSLATION | - | ||||||||||||||||||||||||
| 1857 | /*! | - | ||||||||||||||||||||||||
| 1858 | Adds the translation file \a translationFile to the list of | - | ||||||||||||||||||||||||
| 1859 | translation files to be used for translations. | - | ||||||||||||||||||||||||
| 1860 | - | |||||||||||||||||||||||||
| 1861 | Multiple translation files can be installed. Translations are | - | ||||||||||||||||||||||||
| 1862 | searched for in the reverse order in which they were installed, | - | ||||||||||||||||||||||||
| 1863 | so the most recently installed translation file is searched first | - | ||||||||||||||||||||||||
| 1864 | and the first translation file installed is searched last. | - | ||||||||||||||||||||||||
| 1865 | The search stops as soon as a translation containing a matching | - | ||||||||||||||||||||||||
| 1866 | string is found. | - | ||||||||||||||||||||||||
| 1867 | - | |||||||||||||||||||||||||
| 1868 | Installing or removing a QTranslator, or changing an installed QTranslator | - | ||||||||||||||||||||||||
| 1869 | generates a \l{QEvent::LanguageChange}{LanguageChange} event for the | - | ||||||||||||||||||||||||
| 1870 | QCoreApplication instance. A QGuiApplication instance will propagate the event | - | ||||||||||||||||||||||||
| 1871 | to all toplevel windows, where a reimplementation of changeEvent can | - | ||||||||||||||||||||||||
| 1872 | re-translate the user interface by passing user-visible strings via the | - | ||||||||||||||||||||||||
| 1873 | tr() function to the respective property setters. User-interface classes | - | ||||||||||||||||||||||||
| 1874 | generated by Qt Designer provide a \c retranslateUi() function that can be | - | ||||||||||||||||||||||||
| 1875 | called. | - | ||||||||||||||||||||||||
| 1876 | - | |||||||||||||||||||||||||
| 1877 | The function returns \c true on success and false on failure. | - | ||||||||||||||||||||||||
| 1878 | - | |||||||||||||||||||||||||
| 1879 | \sa removeTranslator(), translate(), QTranslator::load(), {Dynamic Translation} | - | ||||||||||||||||||||||||
| 1880 | */ | - | ||||||||||||||||||||||||
| 1881 | - | |||||||||||||||||||||||||
| 1882 | bool QCoreApplication::installTranslator(QTranslator *translationFile) | - | ||||||||||||||||||||||||
| 1883 | { | - | ||||||||||||||||||||||||
| 1884 | if (!translationFile) | - | ||||||||||||||||||||||||
| 1885 | return false; | - | ||||||||||||||||||||||||
| 1886 | - | |||||||||||||||||||||||||
| 1887 | if (!QCoreApplicationPrivate::checkInstance("installTranslator")) | - | ||||||||||||||||||||||||
| 1888 | return false; | - | ||||||||||||||||||||||||
| 1889 | QCoreApplicationPrivate *d = self->d_func(); | - | ||||||||||||||||||||||||
| 1890 | d->translators.prepend(translationFile); | - | ||||||||||||||||||||||||
| 1891 | - | |||||||||||||||||||||||||
| 1892 | #ifndef QT_NO_TRANSLATION_BUILDER | - | ||||||||||||||||||||||||
| 1893 | if (translationFile->isEmpty()) | - | ||||||||||||||||||||||||
| 1894 | return false; | - | ||||||||||||||||||||||||
| 1895 | #endif | - | ||||||||||||||||||||||||
| 1896 | - | |||||||||||||||||||||||||
| 1897 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1898 | QEvent ev(QEvent::LanguageChange); | - | ||||||||||||||||||||||||
| 1899 | QCoreApplication::sendEvent(self, &ev); | - | ||||||||||||||||||||||||
| 1900 | #endif | - | ||||||||||||||||||||||||
| 1901 | - | |||||||||||||||||||||||||
| 1902 | return true; | - | ||||||||||||||||||||||||
| 1903 | } | - | ||||||||||||||||||||||||
| 1904 | - | |||||||||||||||||||||||||
| 1905 | /*! | - | ||||||||||||||||||||||||
| 1906 | Removes the translation file \a translationFile from the list of | - | ||||||||||||||||||||||||
| 1907 | translation files used by this application. (It does not delete the | - | ||||||||||||||||||||||||
| 1908 | translation file from the file system.) | - | ||||||||||||||||||||||||
| 1909 | - | |||||||||||||||||||||||||
| 1910 | The function returns \c true on success and false on failure. | - | ||||||||||||||||||||||||
| 1911 | - | |||||||||||||||||||||||||
| 1912 | \sa installTranslator(), translate(), QObject::tr() | - | ||||||||||||||||||||||||
| 1913 | */ | - | ||||||||||||||||||||||||
| 1914 | - | |||||||||||||||||||||||||
| 1915 | bool QCoreApplication::removeTranslator(QTranslator *translationFile) | - | ||||||||||||||||||||||||
| 1916 | { | - | ||||||||||||||||||||||||
| 1917 | if (!translationFile) | - | ||||||||||||||||||||||||
| 1918 | return false; | - | ||||||||||||||||||||||||
| 1919 | if (!QCoreApplicationPrivate::checkInstance("removeTranslator")) | - | ||||||||||||||||||||||||
| 1920 | return false; | - | ||||||||||||||||||||||||
| 1921 | QCoreApplicationPrivate *d = self->d_func(); | - | ||||||||||||||||||||||||
| 1922 | if (d->translators.removeAll(translationFile)) { | - | ||||||||||||||||||||||||
| 1923 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 1924 | if (!self->closingDown()) { | - | ||||||||||||||||||||||||
| 1925 | QEvent ev(QEvent::LanguageChange); | - | ||||||||||||||||||||||||
| 1926 | QCoreApplication::sendEvent(self, &ev); | - | ||||||||||||||||||||||||
| 1927 | } | - | ||||||||||||||||||||||||
| 1928 | #endif | - | ||||||||||||||||||||||||
| 1929 | return true; | - | ||||||||||||||||||||||||
| 1930 | } | - | ||||||||||||||||||||||||
| 1931 | return false; | - | ||||||||||||||||||||||||
| 1932 | } | - | ||||||||||||||||||||||||
| 1933 | - | |||||||||||||||||||||||||
| 1934 | static void replacePercentN(QString *result, int n) | - | ||||||||||||||||||||||||
| 1935 | { | - | ||||||||||||||||||||||||
| 1936 | if (n >= 0) { | - | ||||||||||||||||||||||||
| 1937 | int percentPos = 0; | - | ||||||||||||||||||||||||
| 1938 | int len = 0; | - | ||||||||||||||||||||||||
| 1939 | while ((percentPos = result->indexOf(QLatin1Char('%'), percentPos + len)) != -1) { | - | ||||||||||||||||||||||||
| 1940 | len = 1; | - | ||||||||||||||||||||||||
| 1941 | QString fmt; | - | ||||||||||||||||||||||||
| 1942 | if (result->at(percentPos + len) == QLatin1Char('L')) { | - | ||||||||||||||||||||||||
| 1943 | ++len; | - | ||||||||||||||||||||||||
| 1944 | fmt = QLatin1String("%L1"); | - | ||||||||||||||||||||||||
| 1945 | } else { | - | ||||||||||||||||||||||||
| 1946 | fmt = QLatin1String("%1"); | - | ||||||||||||||||||||||||
| 1947 | } | - | ||||||||||||||||||||||||
| 1948 | if (result->at(percentPos + len) == QLatin1Char('n')) { | - | ||||||||||||||||||||||||
| 1949 | fmt = fmt.arg(n); | - | ||||||||||||||||||||||||
| 1950 | ++len; | - | ||||||||||||||||||||||||
| 1951 | result->replace(percentPos, len, fmt); | - | ||||||||||||||||||||||||
| 1952 | len = fmt.length(); | - | ||||||||||||||||||||||||
| 1953 | } | - | ||||||||||||||||||||||||
| 1954 | } | - | ||||||||||||||||||||||||
| 1955 | } | - | ||||||||||||||||||||||||
| 1956 | } | - | ||||||||||||||||||||||||
| 1957 | - | |||||||||||||||||||||||||
| 1958 | /*! | - | ||||||||||||||||||||||||
| 1959 | \reentrant | - | ||||||||||||||||||||||||
| 1960 | - | |||||||||||||||||||||||||
| 1961 | Returns the translation text for \a sourceText, by querying the | - | ||||||||||||||||||||||||
| 1962 | installed translation files. The translation files are searched | - | ||||||||||||||||||||||||
| 1963 | from the most recently installed file back to the first | - | ||||||||||||||||||||||||
| 1964 | installed file. | - | ||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||
| 1966 | QObject::tr() provides this functionality more conveniently. | - | ||||||||||||||||||||||||
| 1967 | - | |||||||||||||||||||||||||
| 1968 | \a context is typically a class name (e.g., "MyDialog") and \a | - | ||||||||||||||||||||||||
| 1969 | sourceText is either English text or a short identifying text. | - | ||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||
| 1971 | \a disambiguation is an identifying string, for when the same \a | - | ||||||||||||||||||||||||
| 1972 | sourceText is used in different roles within the same context. By | - | ||||||||||||||||||||||||
| 1973 | default, it is null. | - | ||||||||||||||||||||||||
| 1974 | - | |||||||||||||||||||||||||
| 1975 | See the \l QTranslator and \l QObject::tr() documentation for | - | ||||||||||||||||||||||||
| 1976 | more information about contexts, disambiguations and comments. | - | ||||||||||||||||||||||||
| 1977 | - | |||||||||||||||||||||||||
| 1978 | \a n is used in conjunction with \c %n to support plural forms. | - | ||||||||||||||||||||||||
| 1979 | See QObject::tr() for details. | - | ||||||||||||||||||||||||
| 1980 | - | |||||||||||||||||||||||||
| 1981 | If none of the translation files contain a translation for \a | - | ||||||||||||||||||||||||
| 1982 | sourceText in \a context, this function returns a QString | - | ||||||||||||||||||||||||
| 1983 | equivalent of \a sourceText. | - | ||||||||||||||||||||||||
| 1984 | - | |||||||||||||||||||||||||
| 1985 | This function is not virtual. You can use alternative translation | - | ||||||||||||||||||||||||
| 1986 | techniques by subclassing \l QTranslator. | - | ||||||||||||||||||||||||
| 1987 | - | |||||||||||||||||||||||||
| 1988 | \warning This method is reentrant only if all translators are | - | ||||||||||||||||||||||||
| 1989 | installed \e before calling this method. Installing or removing | - | ||||||||||||||||||||||||
| 1990 | translators while performing translations is not supported. Doing | - | ||||||||||||||||||||||||
| 1991 | so will most likely result in crashes or other undesirable | - | ||||||||||||||||||||||||
| 1992 | behavior. | - | ||||||||||||||||||||||||
| 1993 | - | |||||||||||||||||||||||||
| 1994 | \sa QObject::tr(), installTranslator() | - | ||||||||||||||||||||||||
| 1995 | */ | - | ||||||||||||||||||||||||
| 1996 | QString QCoreApplication::translate(const char *context, const char *sourceText, | - | ||||||||||||||||||||||||
| 1997 | const char *disambiguation, int n) | - | ||||||||||||||||||||||||
| 1998 | { | - | ||||||||||||||||||||||||
| 1999 | QString result; | - | ||||||||||||||||||||||||
| 2000 | - | |||||||||||||||||||||||||
| 2001 | if (!sourceText) | - | ||||||||||||||||||||||||
| 2002 | return result; | - | ||||||||||||||||||||||||
| 2003 | - | |||||||||||||||||||||||||
| 2004 | if (self && !self->d_func()->translators.isEmpty()) { | - | ||||||||||||||||||||||||
| 2005 | QList<QTranslator*>::ConstIterator it; | - | ||||||||||||||||||||||||
| 2006 | QTranslator *translationFile; | - | ||||||||||||||||||||||||
| 2007 | for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) { | - | ||||||||||||||||||||||||
| 2008 | translationFile = *it; | - | ||||||||||||||||||||||||
| 2009 | result = translationFile->translate(context, sourceText, disambiguation, n); | - | ||||||||||||||||||||||||
| 2010 | if (!result.isNull()) | - | ||||||||||||||||||||||||
| 2011 | break; | - | ||||||||||||||||||||||||
| 2012 | } | - | ||||||||||||||||||||||||
| 2013 | } | - | ||||||||||||||||||||||||
| 2014 | - | |||||||||||||||||||||||||
| 2015 | if (result.isNull()) | - | ||||||||||||||||||||||||
| 2016 | result = QString::fromUtf8(sourceText); | - | ||||||||||||||||||||||||
| 2017 | - | |||||||||||||||||||||||||
| 2018 | replacePercentN(&result, n); | - | ||||||||||||||||||||||||
| 2019 | return result; | - | ||||||||||||||||||||||||
| 2020 | } | - | ||||||||||||||||||||||||
| 2021 | - | |||||||||||||||||||||||||
| 2022 | /*! \fn static QString QCoreApplication::translate(const char *context, const char *key, const char *disambiguation, Encoding encoding, int n = -1) | - | ||||||||||||||||||||||||
| 2023 | - | |||||||||||||||||||||||||
| 2024 | \obsolete | - | ||||||||||||||||||||||||
| 2025 | */ | - | ||||||||||||||||||||||||
| 2026 | - | |||||||||||||||||||||||||
| 2027 | // Declared in qglobal.h | - | ||||||||||||||||||||||||
| 2028 | QString qtTrId(const char *id, int n) | - | ||||||||||||||||||||||||
| 2029 | { | - | ||||||||||||||||||||||||
| 2030 | return QCoreApplication::translate(0, id, 0, n); | - | ||||||||||||||||||||||||
| 2031 | } | - | ||||||||||||||||||||||||
| 2032 | - | |||||||||||||||||||||||||
| 2033 | bool QCoreApplicationPrivate::isTranslatorInstalled(QTranslator *translator) | - | ||||||||||||||||||||||||
| 2034 | { | - | ||||||||||||||||||||||||
| 2035 | return QCoreApplication::self | - | ||||||||||||||||||||||||
| 2036 | && QCoreApplication::self->d_func()->translators.contains(translator); | - | ||||||||||||||||||||||||
| 2037 | } | - | ||||||||||||||||||||||||
| 2038 | - | |||||||||||||||||||||||||
| 2039 | #else | - | ||||||||||||||||||||||||
| 2040 | - | |||||||||||||||||||||||||
| 2041 | QString QCoreApplication::translate(const char *context, const char *sourceText, | - | ||||||||||||||||||||||||
| 2042 | const char *disambiguation, int n) | - | ||||||||||||||||||||||||
| 2043 | { | - | ||||||||||||||||||||||||
| 2044 | Q_UNUSED(context) | - | ||||||||||||||||||||||||
| 2045 | Q_UNUSED(disambiguation) | - | ||||||||||||||||||||||||
| 2046 | QString ret = QString::fromUtf8(sourceText); | - | ||||||||||||||||||||||||
| 2047 | if (n >= 0) | - | ||||||||||||||||||||||||
| 2048 | ret.replace(QLatin1String("%n"), QString::number(n)); | - | ||||||||||||||||||||||||
| 2049 | return ret; | - | ||||||||||||||||||||||||
| 2050 | } | - | ||||||||||||||||||||||||
| 2051 | - | |||||||||||||||||||||||||
| 2052 | #endif //QT_NO_TRANSLATE | - | ||||||||||||||||||||||||
| 2053 | - | |||||||||||||||||||||||||
| 2054 | // Makes it possible to point QCoreApplication to a custom location to ensure | - | ||||||||||||||||||||||||
| 2055 | // the directory is added to the patch, and qt.conf and deployed plugins are | - | ||||||||||||||||||||||||
| 2056 | // found from there. This is for use cases in which QGuiApplication is | - | ||||||||||||||||||||||||
| 2057 | // instantiated by a library and not by an application executable, for example, | - | ||||||||||||||||||||||||
| 2058 | // Active X servers. | - | ||||||||||||||||||||||||
| 2059 | - | |||||||||||||||||||||||||
| 2060 | void QCoreApplicationPrivate::setApplicationFilePath(const QString &path) | - | ||||||||||||||||||||||||
| 2061 | { | - | ||||||||||||||||||||||||
| 2062 | if (QCoreApplicationPrivate::cachedApplicationFilePath) | - | ||||||||||||||||||||||||
| 2063 | *QCoreApplicationPrivate::cachedApplicationFilePath = path; | - | ||||||||||||||||||||||||
| 2064 | else | - | ||||||||||||||||||||||||
| 2065 | QCoreApplicationPrivate::cachedApplicationFilePath = new QString(path); | - | ||||||||||||||||||||||||
| 2066 | } | - | ||||||||||||||||||||||||
| 2067 | - | |||||||||||||||||||||||||
| 2068 | /*! | - | ||||||||||||||||||||||||
| 2069 | Returns the directory that contains the application executable. | - | ||||||||||||||||||||||||
| 2070 | - | |||||||||||||||||||||||||
| 2071 | For example, if you have installed Qt in the \c{C:\Qt} | - | ||||||||||||||||||||||||
| 2072 | directory, and you run the \c{regexp} example, this function will | - | ||||||||||||||||||||||||
| 2073 | return "C:/Qt/examples/tools/regexp". | - | ||||||||||||||||||||||||
| 2074 | - | |||||||||||||||||||||||||
| 2075 | On \macos and iOS this will point to the directory actually containing | - | ||||||||||||||||||||||||
| 2076 | the executable, which may be inside an application bundle (if the | - | ||||||||||||||||||||||||
| 2077 | application is bundled). | - | ||||||||||||||||||||||||
| 2078 | - | |||||||||||||||||||||||||
| 2079 | \warning On Linux, this function will try to get the path from the | - | ||||||||||||||||||||||||
| 2080 | \c {/proc} file system. If that fails, it assumes that \c | - | ||||||||||||||||||||||||
| 2081 | {argv[0]} contains the absolute file name of the executable. The | - | ||||||||||||||||||||||||
| 2082 | function also assumes that the current directory has not been | - | ||||||||||||||||||||||||
| 2083 | changed by the application. | - | ||||||||||||||||||||||||
| 2084 | - | |||||||||||||||||||||||||
| 2085 | \sa applicationFilePath() | - | ||||||||||||||||||||||||
| 2086 | */ | - | ||||||||||||||||||||||||
| 2087 | QString QCoreApplication::applicationDirPath() | - | ||||||||||||||||||||||||
| 2088 | { | - | ||||||||||||||||||||||||
| 2089 | if (!self) { | - | ||||||||||||||||||||||||
| 2090 | qWarning("QCoreApplication::applicationDirPath: Please instantiate the QApplication object first"); | - | ||||||||||||||||||||||||
| 2091 | return QString(); | - | ||||||||||||||||||||||||
| 2092 | } | - | ||||||||||||||||||||||||
| 2093 | - | |||||||||||||||||||||||||
| 2094 | QCoreApplicationPrivate *d = self->d_func(); | - | ||||||||||||||||||||||||
| 2095 | if (d->cachedApplicationDirPath.isNull()) | - | ||||||||||||||||||||||||
| 2096 | d->cachedApplicationDirPath = QFileInfo(applicationFilePath()).path(); | - | ||||||||||||||||||||||||
| 2097 | return d->cachedApplicationDirPath; | - | ||||||||||||||||||||||||
| 2098 | } | - | ||||||||||||||||||||||||
| 2099 | - | |||||||||||||||||||||||||
| 2100 | /*! | - | ||||||||||||||||||||||||
| 2101 | Returns the file path of the application executable. | - | ||||||||||||||||||||||||
| 2102 | - | |||||||||||||||||||||||||
| 2103 | For example, if you have installed Qt in the \c{/usr/local/qt} | - | ||||||||||||||||||||||||
| 2104 | directory, and you run the \c{regexp} example, this function will | - | ||||||||||||||||||||||||
| 2105 | return "/usr/local/qt/examples/tools/regexp/regexp". | - | ||||||||||||||||||||||||
| 2106 | - | |||||||||||||||||||||||||
| 2107 | \warning On Linux, this function will try to get the path from the | - | ||||||||||||||||||||||||
| 2108 | \c {/proc} file system. If that fails, it assumes that \c | - | ||||||||||||||||||||||||
| 2109 | {argv[0]} contains the absolute file name of the executable. The | - | ||||||||||||||||||||||||
| 2110 | function also assumes that the current directory has not been | - | ||||||||||||||||||||||||
| 2111 | changed by the application. | - | ||||||||||||||||||||||||
| 2112 | - | |||||||||||||||||||||||||
| 2113 | \sa applicationDirPath() | - | ||||||||||||||||||||||||
| 2114 | */ | - | ||||||||||||||||||||||||
| 2115 | QString QCoreApplication::applicationFilePath() | - | ||||||||||||||||||||||||
| 2116 | { | - | ||||||||||||||||||||||||
| 2117 | if (!self) {
| 0-1036 | ||||||||||||||||||||||||
| 2118 | qWarning("QCoreApplication::applicationFilePath: Please instantiate the QApplication object first"); | - | ||||||||||||||||||||||||
| 2119 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 2120 | } | - | ||||||||||||||||||||||||
| 2121 | - | |||||||||||||||||||||||||
| 2122 | QCoreApplicationPrivate *d = self->d_func(); | - | ||||||||||||||||||||||||
| 2123 | - | |||||||||||||||||||||||||
| 2124 | if (d->argc) {
| 82-954 | ||||||||||||||||||||||||
| 2125 | static const char *procName = d->argv[0]; | - | ||||||||||||||||||||||||
| 2126 | if (qstrcmp(procName, d->argv[0]) != 0) {
| 5-949 | ||||||||||||||||||||||||
| 2127 | // clear the cache if the procname changes, so we reprocess it. | - | ||||||||||||||||||||||||
| 2128 | QCoreApplicationPrivate::clearApplicationFilePath(); | - | ||||||||||||||||||||||||
| 2129 | procName = d->argv[0]; | - | ||||||||||||||||||||||||
| 2130 | } executed 5 times by 2 tests: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 2131 | } executed 954 times by 49 tests: end of blockExecuted by:
| 954 | ||||||||||||||||||||||||
| 2132 | - | |||||||||||||||||||||||||
| 2133 | if (QCoreApplicationPrivate::cachedApplicationFilePath)
| 82-954 | ||||||||||||||||||||||||
| 2134 | return *QCoreApplicationPrivate::cachedApplicationFilePath; executed 82 times by 36 tests: return *QCoreApplicationPrivate::cachedApplicationFilePath;Executed by:
| 82 | ||||||||||||||||||||||||
| 2135 | - | |||||||||||||||||||||||||
| 2136 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 2137 | QCoreApplicationPrivate::setApplicationFilePath(QFileInfo(qAppFileName()).filePath()); | - | ||||||||||||||||||||||||
| 2138 | return *QCoreApplicationPrivate::cachedApplicationFilePath; | - | ||||||||||||||||||||||||
| #elif defined(Q_OS_BLACKBERRY) | ||||||||||||||||||||||||||
| if (!arguments().isEmpty()) { QFileInfo fileInfo(arguments().at(0)); | ||||||||||||||||||||||||||
| const bool zygotized = fileInfo.exists(); | ||||||||||||||||||||||||||
| if (zygotized) { | ||||||||||||||||||||||||||
| QCoreApplicationPrivate::setApplicationFilePath(QDir::cleanPath(fileInfo.absoluteFilePath())); | ||||||||||||||||||||||||||
| return *QCoreApplicationPrivate::cachedApplicationFilePath; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| const size_t maximum_path = static_cast<size_t>(pathconf("/",_PC_PATH_MAX)); | ||||||||||||||||||||||||||
| char buff[maximum_path+1]; | ||||||||||||||||||||||||||
| if (_cmdname(buff)) { | ||||||||||||||||||||||||||
| QCoreApplicationPrivate::setApplicationFilePath(QDir::cleanPath(QString::fromLocal8Bit(buff))); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| qWarning("QCoreApplication::applicationFilePath: _cmdname() failed"); | ||||||||||||||||||||||||||
| QDir dir(QStringLiteral("./app/native/")); | ||||||||||||||||||||||||||
| QStringList executables = dir.entryList(QDir::Executable | QDir::Files); | ||||||||||||||||||||||||||
| if (!executables.empty()) { | ||||||||||||||||||||||||||
| QCoreApplicationPrivate::setApplicationFilePath(dir.absoluteFilePath(executables.first())); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }return *QCoreApplicationPrivate::cachedApplicationFilePath; | ||||||||||||||||||||||||||
| 2139 | #elif defined(Q_OS_MAC) | - | ||||||||||||||||||||||||
| 2140 | QString qAppFileName_str = qAppFileName(); | - | ||||||||||||||||||||||||
| 2141 | if(!qAppFileName_str.isEmpty()) { | - | ||||||||||||||||||||||||
| 2142 | QFileInfo fi(qAppFileName_str); | - | ||||||||||||||||||||||||
| 2143 | if (fi.exists()) { | - | ||||||||||||||||||||||||
| 2144 | QCoreApplicationPrivate::setApplicationFilePath(fi.canonicalFilePath()); | - | ||||||||||||||||||||||||
| 2145 | return *QCoreApplicationPrivate::cachedApplicationFilePath; | - | ||||||||||||||||||||||||
| 2146 | } | - | ||||||||||||||||||||||||
| 2147 | return QString();} | - | ||||||||||||||||||||||||
| 2148 | #endif | - | ||||||||||||||||||||||||
| 2149 | #if defined( Q_OS_UNIX ) | - | ||||||||||||||||||||||||
| 2150 | # if defined(Q_OS_LINUX) && (!!defined(Q_OS_ANDROID) | - | ||||||||||||||||||||||||
| 2151 | || defined(Q_OS_ANDROID_NO_SDK))// Try looking for a /proc/<pid>/exe symlink first which points to | - | ||||||||||||||||||||||||
| 2152 | // the absolute path of the executable | - | ||||||||||||||||||||||||
| 2153 | QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid())); | - | ||||||||||||||||||||||||
| 2154 | if (pfi.exists() && pfi.isSymLink()) {
| 0-954 | ||||||||||||||||||||||||
| 2155 | QCoreApplicationPrivate::setApplicationFilePath(pfi.canonicalFilePath()); | - | ||||||||||||||||||||||||
| 2156 | return *QCoreApplicationPrivate::cachedApplicationFilePath; executed 954 times by 23 tests: return *QCoreApplicationPrivate::cachedApplicationFilePath;Executed by:
| 954 | ||||||||||||||||||||||||
| 2157 | } | - | ||||||||||||||||||||||||
| 2158 | # endif | - | ||||||||||||||||||||||||
| 2159 | if (!arguments().isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 2160 | QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit()); | - | ||||||||||||||||||||||||
| 2161 | QString absPath; | - | ||||||||||||||||||||||||
| 2162 | - | |||||||||||||||||||||||||
| 2163 | if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
| 0 | ||||||||||||||||||||||||
| 2164 | /* | - | ||||||||||||||||||||||||
| 2165 | If argv0 starts with a slash, it is already an absolute | - | ||||||||||||||||||||||||
| 2166 | file path. | - | ||||||||||||||||||||||||
| 2167 | */ | - | ||||||||||||||||||||||||
| 2168 | absPath = argv0; | - | ||||||||||||||||||||||||
| 2169 | } else if (argv0.contains(QLatin1Char('/'))) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2170 | /* | - | ||||||||||||||||||||||||
| 2171 | If argv0 contains one or more slashes, it is a file path | - | ||||||||||||||||||||||||
| 2172 | relative to the current directory. | - | ||||||||||||||||||||||||
| 2173 | */ | - | ||||||||||||||||||||||||
| 2174 | absPath = QDir::current().absoluteFilePath(argv0); | - | ||||||||||||||||||||||||
| 2175 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2176 | /* | - | ||||||||||||||||||||||||
| 2177 | Otherwise, the file path has to be determined using the | - | ||||||||||||||||||||||||
| 2178 | PATH environment variable. | - | ||||||||||||||||||||||||
| 2179 | */ | - | ||||||||||||||||||||||||
| 2180 | absPath = QStandardPaths::findExecutable(argv0); | - | ||||||||||||||||||||||||
| 2181 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2182 | - | |||||||||||||||||||||||||
| 2183 | absPath = QDir::cleanPath(absPath); | - | ||||||||||||||||||||||||
| 2184 | - | |||||||||||||||||||||||||
| 2185 | QFileInfo fi(absPath); | - | ||||||||||||||||||||||||
| 2186 | if (fi.exists()) {
| 0 | ||||||||||||||||||||||||
| 2187 | QCoreApplicationPrivate::setApplicationFilePath(fi.canonicalFilePath()); | - | ||||||||||||||||||||||||
| 2188 | return *QCoreApplicationPrivate::cachedApplicationFilePath; never executed: return *QCoreApplicationPrivate::cachedApplicationFilePath; | 0 | ||||||||||||||||||||||||
| 2189 | } | - | ||||||||||||||||||||||||
| 2190 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2191 | - | |||||||||||||||||||||||||
| 2192 | #endif | - | ||||||||||||||||||||||||
| 2193 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| #endif never executed: return QString(); | ||||||||||||||||||||||||||
| Q_UNREACHABLE never executed: ();return QString();never executed: return QString(); | ||||||||||||||||||||||||||
| 2194 | } | - | ||||||||||||||||||||||||
| 2195 | - | |||||||||||||||||||||||||
| 2196 | /*! | - | ||||||||||||||||||||||||
| 2197 | \since 4.4 | - | ||||||||||||||||||||||||
| 2198 | - | |||||||||||||||||||||||||
| 2199 | Returns the current process ID for the application. | - | ||||||||||||||||||||||||
| 2200 | */ | - | ||||||||||||||||||||||||
| 2201 | qint64 QCoreApplication::applicationPid() | - | ||||||||||||||||||||||||
| 2202 | { | - | ||||||||||||||||||||||||
| 2203 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 2204 | return GetCurrentProcessId(); | - | ||||||||||||||||||||||||
| 2205 | #elif defined(Q_OS_VXWORKS) | - | ||||||||||||||||||||||||
| 2206 | return (pid_t) taskIdCurrent; | - | ||||||||||||||||||||||||
| 2207 | #else | - | ||||||||||||||||||||||||
| 2208 | return getpid(); | - | ||||||||||||||||||||||||
| 2209 | #endif | - | ||||||||||||||||||||||||
| 2210 | } | - | ||||||||||||||||||||||||
| 2211 | - | |||||||||||||||||||||||||
| 2212 | /*! | - | ||||||||||||||||||||||||
| 2213 | \since 4.1 | - | ||||||||||||||||||||||||
| 2214 | - | |||||||||||||||||||||||||
| 2215 | Returns the list of command-line arguments. | - | ||||||||||||||||||||||||
| 2216 | - | |||||||||||||||||||||||||
| 2217 | Usually arguments().at(0) is the program name, arguments().at(1) | - | ||||||||||||||||||||||||
| 2218 | is the first argument, and arguments().last() is the last | - | ||||||||||||||||||||||||
| 2219 | argument. See the note below about Windows. | - | ||||||||||||||||||||||||
| 2220 | - | |||||||||||||||||||||||||
| 2221 | Calling this function is slow - you should store the result in a variable | - | ||||||||||||||||||||||||
| 2222 | when parsing the command line. | - | ||||||||||||||||||||||||
| 2223 | - | |||||||||||||||||||||||||
| 2224 | \warning On Unix, this list is built from the argc and argv parameters passed | - | ||||||||||||||||||||||||
| 2225 | to the constructor in the main() function. The string-data in argv is | - | ||||||||||||||||||||||||
| 2226 | interpreted using QString::fromLocal8Bit(); hence it is not possible to | - | ||||||||||||||||||||||||
| 2227 | pass, for example, Japanese command line arguments on a system that runs in a | - | ||||||||||||||||||||||||
| 2228 | Latin1 locale. Most modern Unix systems do not have this limitation, as they are | - | ||||||||||||||||||||||||
| 2229 | Unicode-based. | - | ||||||||||||||||||||||||
| 2230 | - | |||||||||||||||||||||||||
| 2231 | On Windows, the list is built from the argc and argv parameters only if | - | ||||||||||||||||||||||||
| 2232 | modified argv/argc parameters are passed to the constructor. In that case, | - | ||||||||||||||||||||||||
| 2233 | encoding problems might occur. | - | ||||||||||||||||||||||||
| 2234 | - | |||||||||||||||||||||||||
| 2235 | Otherwise, the arguments() are constructed from the return value of | - | ||||||||||||||||||||||||
| 2236 | \l{http://msdn2.microsoft.com/en-us/library/ms683156(VS.85).aspx}{GetCommandLine()}. | - | ||||||||||||||||||||||||
| 2237 | As a result of this, the string given by arguments().at(0) might not be | - | ||||||||||||||||||||||||
| 2238 | the program name on Windows, depending on how the application was started. | - | ||||||||||||||||||||||||
| 2239 | - | |||||||||||||||||||||||||
| 2240 | \sa applicationFilePath(), QCommandLineParser | - | ||||||||||||||||||||||||
| 2241 | */ | - | ||||||||||||||||||||||||
| 2242 | - | |||||||||||||||||||||||||
| 2243 | QStringList QCoreApplication::arguments() | - | ||||||||||||||||||||||||
| 2244 | { | - | ||||||||||||||||||||||||
| 2245 | QStringList list; | - | ||||||||||||||||||||||||
| 2246 | - | |||||||||||||||||||||||||
| 2247 | if (!self) { | - | ||||||||||||||||||||||||
| 2248 | qWarning("QCoreApplication::arguments: Please instantiate the QApplication object first"); | - | ||||||||||||||||||||||||
| 2249 | return list; | - | ||||||||||||||||||||||||
| 2250 | } | - | ||||||||||||||||||||||||
| 2251 | const int ac = self->d_func()->argc; | - | ||||||||||||||||||||||||
| 2252 | char ** const av = self->d_func()->argv; | - | ||||||||||||||||||||||||
| 2253 | list.reserve(ac); | - | ||||||||||||||||||||||||
| 2254 | - | |||||||||||||||||||||||||
| 2255 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 2256 | // On Windows, it is possible to pass Unicode arguments on | - | ||||||||||||||||||||||||
| 2257 | // the command line. To restore those, we split the command line | - | ||||||||||||||||||||||||
| 2258 | // and filter out arguments that were deleted by derived application | - | ||||||||||||||||||||||||
| 2259 | // classes by index. | - | ||||||||||||||||||||||||
| 2260 | QString cmdline = QString::fromWCharArray(GetCommandLine()); | - | ||||||||||||||||||||||||
| 2261 | - | |||||||||||||||||||||||||
| 2262 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 2263 | wchar_t tempFilename[MAX_PATH+1]; | - | ||||||||||||||||||||||||
| 2264 | if (GetModuleFileName(0, tempFilename, MAX_PATH)) { | - | ||||||||||||||||||||||||
| 2265 | tempFilename[MAX_PATH] = 0; | - | ||||||||||||||||||||||||
| 2266 | cmdline.prepend(QLatin1Char('\"') + QString::fromWCharArray(tempFilename) + QLatin1String("\" ")); | - | ||||||||||||||||||||||||
| 2267 | } | - | ||||||||||||||||||||||||
| 2268 | #endif // Q_OS_WINCE | - | ||||||||||||||||||||||||
| 2269 | - | |||||||||||||||||||||||||
| 2270 | const QCoreApplicationPrivate *d = self->d_func(); | - | ||||||||||||||||||||||||
| 2271 | if (d->origArgv) { | - | ||||||||||||||||||||||||
| 2272 | const QStringList allArguments = qWinCmdArgs(cmdline); | - | ||||||||||||||||||||||||
| 2273 | Q_ASSERT(allArguments.size() == d->origArgc); | - | ||||||||||||||||||||||||
| 2274 | for (int i = 0; i < d->origArgc; ++i) { | - | ||||||||||||||||||||||||
| 2275 | if (contains(ac, av, d->origArgv[i])) | - | ||||||||||||||||||||||||
| 2276 | list.append(allArguments.at(i)); | - | ||||||||||||||||||||||||
| 2277 | } | - | ||||||||||||||||||||||||
| 2278 | return list; | - | ||||||||||||||||||||||||
| 2279 | } // Fall back to rebuilding from argv/argc when a modified argv was passed. | - | ||||||||||||||||||||||||
| 2280 | #endif // defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 2281 | - | |||||||||||||||||||||||||
| 2282 | for (int a = 0; a < ac; ++a) { | - | ||||||||||||||||||||||||
| 2283 | list << QString::fromLocal8Bit(av[a]); | - | ||||||||||||||||||||||||
| 2284 | } | - | ||||||||||||||||||||||||
| 2285 | - | |||||||||||||||||||||||||
| 2286 | return list; | - | ||||||||||||||||||||||||
| 2287 | } | - | ||||||||||||||||||||||||
| 2288 | - | |||||||||||||||||||||||||
| 2289 | /*! | - | ||||||||||||||||||||||||
| 2290 | \property QCoreApplication::organizationName | - | ||||||||||||||||||||||||
| 2291 | \brief the name of the organization that wrote this application | - | ||||||||||||||||||||||||
| 2292 | - | |||||||||||||||||||||||||
| 2293 | The value is used by the QSettings class when it is constructed | - | ||||||||||||||||||||||||
| 2294 | using the empty constructor. This saves having to repeat this | - | ||||||||||||||||||||||||
| 2295 | information each time a QSettings object is created. | - | ||||||||||||||||||||||||
| 2296 | - | |||||||||||||||||||||||||
| 2297 | On Mac, QSettings uses \l {QCoreApplication::}{organizationDomain()} as the organization | - | ||||||||||||||||||||||||
| 2298 | if it's not an empty string; otherwise it uses | - | ||||||||||||||||||||||||
| 2299 | organizationName(). On all other platforms, QSettings uses | - | ||||||||||||||||||||||||
| 2300 | organizationName() as the organization. | - | ||||||||||||||||||||||||
| 2301 | - | |||||||||||||||||||||||||
| 2302 | \sa organizationDomain, applicationName | - | ||||||||||||||||||||||||
| 2303 | */ | - | ||||||||||||||||||||||||
| 2304 | - | |||||||||||||||||||||||||
| 2305 | /*! | - | ||||||||||||||||||||||||
| 2306 | \fn void QCoreApplication::organizationNameChanged() | - | ||||||||||||||||||||||||
| 2307 | \internal | - | ||||||||||||||||||||||||
| 2308 | - | |||||||||||||||||||||||||
| 2309 | While not useful from C++ due to how organizationName is normally set once on | - | ||||||||||||||||||||||||
| 2310 | startup, this is still needed for QML so that bindings are reevaluated after | - | ||||||||||||||||||||||||
| 2311 | that initial change. | - | ||||||||||||||||||||||||
| 2312 | */ | - | ||||||||||||||||||||||||
| 2313 | void QCoreApplication::setOrganizationName(const QString &orgName) | - | ||||||||||||||||||||||||
| 2314 | { | - | ||||||||||||||||||||||||
| 2315 | if (coreappdata()->orgName == orgName) | - | ||||||||||||||||||||||||
| 2316 | return; | - | ||||||||||||||||||||||||
| 2317 | coreappdata()->orgName = orgName; | - | ||||||||||||||||||||||||
| 2318 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2319 | if (QCoreApplication::self) | - | ||||||||||||||||||||||||
| 2320 | emit QCoreApplication::self->organizationNameChanged(); | - | ||||||||||||||||||||||||
| 2321 | #endif | - | ||||||||||||||||||||||||
| 2322 | } | - | ||||||||||||||||||||||||
| 2323 | - | |||||||||||||||||||||||||
| 2324 | QString QCoreApplication::organizationName() | - | ||||||||||||||||||||||||
| 2325 | { | - | ||||||||||||||||||||||||
| 2326 | #ifdef Q_OS_BLACKBERRY executed 46 times by 3 tests: return coreappdata()->orgName;Executed by:
| 46 | ||||||||||||||||||||||||
| coreappdata()->loadManifest(); executed 46 times by 3 tests: return coreappdata()->orgName;Executed by:
| ||||||||||||||||||||||||||
| #endif executed 46 times by 3 tests: return coreappdata()->orgName;return coreappdata()->orgName;Executed by:
executed 46 times by 3 tests: return coreappdata()->orgName;Executed by:
| ||||||||||||||||||||||||||
| 2327 | } | - | ||||||||||||||||||||||||
| 2328 | - | |||||||||||||||||||||||||
| 2329 | /*! | - | ||||||||||||||||||||||||
| 2330 | \property QCoreApplication::organizationDomain | - | ||||||||||||||||||||||||
| 2331 | \brief the Internet domain of the organization that wrote this application | - | ||||||||||||||||||||||||
| 2332 | - | |||||||||||||||||||||||||
| 2333 | The value is used by the QSettings class when it is constructed | - | ||||||||||||||||||||||||
| 2334 | using the empty constructor. This saves having to repeat this | - | ||||||||||||||||||||||||
| 2335 | information each time a QSettings object is created. | - | ||||||||||||||||||||||||
| 2336 | - | |||||||||||||||||||||||||
| 2337 | On Mac, QSettings uses organizationDomain() as the organization | - | ||||||||||||||||||||||||
| 2338 | if it's not an empty string; otherwise it uses organizationName(). | - | ||||||||||||||||||||||||
| 2339 | On all other platforms, QSettings uses organizationName() as the | - | ||||||||||||||||||||||||
| 2340 | organization. | - | ||||||||||||||||||||||||
| 2341 | - | |||||||||||||||||||||||||
| 2342 | \sa organizationName, applicationName, applicationVersion | - | ||||||||||||||||||||||||
| 2343 | */ | - | ||||||||||||||||||||||||
| 2344 | /*! | - | ||||||||||||||||||||||||
| 2345 | \fn void QCoreApplication::organizationDomainChanged() | - | ||||||||||||||||||||||||
| 2346 | \internal | - | ||||||||||||||||||||||||
| 2347 | - | |||||||||||||||||||||||||
| 2348 | Primarily for QML, see organizationNameChanged. | - | ||||||||||||||||||||||||
| 2349 | */ | - | ||||||||||||||||||||||||
| 2350 | void QCoreApplication::setOrganizationDomain(const QString &orgDomain) | - | ||||||||||||||||||||||||
| 2351 | { | - | ||||||||||||||||||||||||
| 2352 | if (coreappdata()->orgDomain == orgDomain) | - | ||||||||||||||||||||||||
| 2353 | return; | - | ||||||||||||||||||||||||
| 2354 | coreappdata()->orgDomain = orgDomain; | - | ||||||||||||||||||||||||
| 2355 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2356 | if (QCoreApplication::self) | - | ||||||||||||||||||||||||
| 2357 | emit QCoreApplication::self->organizationDomainChanged(); | - | ||||||||||||||||||||||||
| 2358 | #endif | - | ||||||||||||||||||||||||
| 2359 | } | - | ||||||||||||||||||||||||
| 2360 | - | |||||||||||||||||||||||||
| 2361 | QString QCoreApplication::organizationDomain() | - | ||||||||||||||||||||||||
| 2362 | { | - | ||||||||||||||||||||||||
| 2363 | return coreappdata()->orgDomain; | - | ||||||||||||||||||||||||
| 2364 | } | - | ||||||||||||||||||||||||
| 2365 | - | |||||||||||||||||||||||||
| 2366 | /*! | - | ||||||||||||||||||||||||
| 2367 | \property QCoreApplication::applicationName | - | ||||||||||||||||||||||||
| 2368 | \brief the name of this application | - | ||||||||||||||||||||||||
| 2369 | - | |||||||||||||||||||||||||
| 2370 | The value is used by the QSettings class when it is constructed | - | ||||||||||||||||||||||||
| 2371 | using the empty constructor. This saves having to repeat this | - | ||||||||||||||||||||||||
| 2372 | information each time a QSettings object is created. | - | ||||||||||||||||||||||||
| 2373 | - | |||||||||||||||||||||||||
| 2374 | If not set, the application name defaults to the executable name (since 5.0). | - | ||||||||||||||||||||||||
| 2375 | - | |||||||||||||||||||||||||
| 2376 | \sa organizationName, organizationDomain, applicationVersion, applicationFilePath() | - | ||||||||||||||||||||||||
| 2377 | */ | - | ||||||||||||||||||||||||
| 2378 | /*! | - | ||||||||||||||||||||||||
| 2379 | \fn void QCoreApplication::applicationNameChanged() | - | ||||||||||||||||||||||||
| 2380 | \internal | - | ||||||||||||||||||||||||
| 2381 | - | |||||||||||||||||||||||||
| 2382 | Primarily for QML, see organizationNameChanged. | - | ||||||||||||||||||||||||
| 2383 | */ | - | ||||||||||||||||||||||||
| 2384 | void QCoreApplication::setApplicationName(const QString &application) | - | ||||||||||||||||||||||||
| 2385 | { | - | ||||||||||||||||||||||||
| 2386 | coreappdata()->applicationNameSet = !application.isEmpty(); | - | ||||||||||||||||||||||||
| 2387 | QString newAppName = application; | - | ||||||||||||||||||||||||
| 2388 | if (newAppName.isEmpty() && QCoreApplication::self) | - | ||||||||||||||||||||||||
| 2389 | newAppName = QCoreApplication::self->d_func()->appName(); | - | ||||||||||||||||||||||||
| 2390 | if (coreappdata()->application == newAppName) | - | ||||||||||||||||||||||||
| 2391 | return; | - | ||||||||||||||||||||||||
| 2392 | coreappdata()->application = newAppName; | - | ||||||||||||||||||||||||
| 2393 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2394 | if (QCoreApplication::self) | - | ||||||||||||||||||||||||
| 2395 | emit QCoreApplication::self->applicationNameChanged(); | - | ||||||||||||||||||||||||
| 2396 | #endif | - | ||||||||||||||||||||||||
| 2397 | } | - | ||||||||||||||||||||||||
| 2398 | - | |||||||||||||||||||||||||
| 2399 | QString QCoreApplication::applicationName() | - | ||||||||||||||||||||||||
| 2400 | { | - | ||||||||||||||||||||||||
| 2401 | #ifdef Q_OS_BLACKBERRY executed 9967 times by 157 tests: return coreappdata() ? coreappdata()->application : QString();Executed by:
| 9967 | ||||||||||||||||||||||||
| coreappdata()->loadManifest(); executed 9967 times by 157 tests: return coreappdata() ? coreappdata()->application : QString();Executed by:
| ||||||||||||||||||||||||||
| #endif executed 9967 times by 157 tests: return coreappdata() ? coreappdata()->application : QString();return coreappdata() ? coreappdata()->application : QString();Executed by:
executed 9967 times by 157 tests: return coreappdata() ? coreappdata()->application : QString();Executed by:
| ||||||||||||||||||||||||||
| 2402 | } | - | ||||||||||||||||||||||||
| 2403 | - | |||||||||||||||||||||||||
| 2404 | // Exported for QDesktopServices (Qt4 behavior compatibility) | - | ||||||||||||||||||||||||
| 2405 | Q_CORE_EXPORT QString qt_applicationName_noFallback() | - | ||||||||||||||||||||||||
| 2406 | { | - | ||||||||||||||||||||||||
| 2407 | return coreappdata()->applicationNameSet ? coreappdata()->application : QString(); | - | ||||||||||||||||||||||||
| 2408 | } | - | ||||||||||||||||||||||||
| 2409 | - | |||||||||||||||||||||||||
| 2410 | /*! | - | ||||||||||||||||||||||||
| 2411 | \property QCoreApplication::applicationVersion | - | ||||||||||||||||||||||||
| 2412 | \since 4.4 | - | ||||||||||||||||||||||||
| 2413 | \brief the version of this application | - | ||||||||||||||||||||||||
| 2414 | - | |||||||||||||||||||||||||
| 2415 | \sa applicationName, organizationName, organizationDomain | - | ||||||||||||||||||||||||
| 2416 | */ | - | ||||||||||||||||||||||||
| 2417 | /*! | - | ||||||||||||||||||||||||
| 2418 | \fn void QCoreApplication::applicationVersionChanged() | - | ||||||||||||||||||||||||
| 2419 | \internal | - | ||||||||||||||||||||||||
| 2420 | - | |||||||||||||||||||||||||
| 2421 | Primarily for QML, see organizationNameChanged. | - | ||||||||||||||||||||||||
| 2422 | */ | - | ||||||||||||||||||||||||
| 2423 | void QCoreApplication::setApplicationVersion(const QString &version) | - | ||||||||||||||||||||||||
| 2424 | { | - | ||||||||||||||||||||||||
| 2425 | if (coreappdata()->applicationVersion == version) | - | ||||||||||||||||||||||||
| 2426 | return; | - | ||||||||||||||||||||||||
| 2427 | coreappdata()->applicationVersion = version; | - | ||||||||||||||||||||||||
| 2428 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2429 | if (QCoreApplication::self) | - | ||||||||||||||||||||||||
| 2430 | emit QCoreApplication::self->applicationVersionChanged(); | - | ||||||||||||||||||||||||
| 2431 | #endif | - | ||||||||||||||||||||||||
| 2432 | } | - | ||||||||||||||||||||||||
| 2433 | - | |||||||||||||||||||||||||
| 2434 | QString QCoreApplication::applicationVersion() | - | ||||||||||||||||||||||||
| 2435 | { | - | ||||||||||||||||||||||||
| 2436 | #ifdef Q_OS_BLACKBERRY executed 8 times by 2 tests: return coreappdata()->applicationVersion;Executed by:
| 8 | ||||||||||||||||||||||||
| coreappdata()->loadManifest(); executed 8 times by 2 tests: return coreappdata()->applicationVersion;Executed by:
| ||||||||||||||||||||||||||
| #endif executed 8 times by 2 tests: return coreappdata()->applicationVersion;return coreappdata()->applicationVersion;Executed by:
executed 8 times by 2 tests: return coreappdata()->applicationVersion;Executed by:
| ||||||||||||||||||||||||||
| 2437 | } | - | ||||||||||||||||||||||||
| 2438 | - | |||||||||||||||||||||||||
| 2439 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 2440 | - | |||||||||||||||||||||||||
| 2441 | Q_GLOBAL_STATIC_WITH_ARGS(QMutex, libraryPathMutex, (QMutex::Recursive)) | - | ||||||||||||||||||||||||
| 2442 | - | |||||||||||||||||||||||||
| 2443 | /*! | - | ||||||||||||||||||||||||
| 2444 | Returns a list of paths that the application will search when | - | ||||||||||||||||||||||||
| 2445 | dynamically loading libraries. | - | ||||||||||||||||||||||||
| 2446 | - | |||||||||||||||||||||||||
| 2447 | The return value of this function may change when a QCoreApplication | - | ||||||||||||||||||||||||
| 2448 | is created. It is not recommended to call it before creating a | - | ||||||||||||||||||||||||
| 2449 | QCoreApplication. The directory of the application executable (\b not | - | ||||||||||||||||||||||||
| 2450 | the working directory) is part of the list if it is known. In order | - | ||||||||||||||||||||||||
| 2451 | to make it known a QCoreApplication has to be constructed as it will | - | ||||||||||||||||||||||||
| 2452 | use \c {argv[0]} to find it. | - | ||||||||||||||||||||||||
| 2453 | - | |||||||||||||||||||||||||
| 2454 | Qt provides default library paths, but they can also be set using | - | ||||||||||||||||||||||||
| 2455 | a \l{Using qt.conf}{qt.conf} file. Paths specified in this file | - | ||||||||||||||||||||||||
| 2456 | will override default values. Note that if the qt.conf file is in | - | ||||||||||||||||||||||||
| 2457 | the directory of the application executable, it may not be found | - | ||||||||||||||||||||||||
| 2458 | until a QCoreApplication is created. If it is not found when calling | - | ||||||||||||||||||||||||
| 2459 | this function, the default library paths will be used. | - | ||||||||||||||||||||||||
| 2460 | - | |||||||||||||||||||||||||
| 2461 | The list will include the installation directory for plugins if | - | ||||||||||||||||||||||||
| 2462 | it exists (the default installation directory for plugins is \c | - | ||||||||||||||||||||||||
| 2463 | INSTALL/plugins, where \c INSTALL is the directory where Qt was | - | ||||||||||||||||||||||||
| 2464 | installed). The colon separated entries of the \c QT_PLUGIN_PATH | - | ||||||||||||||||||||||||
| 2465 | environment variable are always added. The plugin installation | - | ||||||||||||||||||||||||
| 2466 | directory (and its existence) may change when the directory of | - | ||||||||||||||||||||||||
| 2467 | the application executable becomes known. | - | ||||||||||||||||||||||||
| 2468 | - | |||||||||||||||||||||||||
| 2469 | If you want to iterate over the list, you can use the \l foreach | - | ||||||||||||||||||||||||
| 2470 | pseudo-keyword: | - | ||||||||||||||||||||||||
| 2471 | - | |||||||||||||||||||||||||
| 2472 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 2 | - | ||||||||||||||||||||||||
| 2473 | - | |||||||||||||||||||||||||
| 2474 | \sa setLibraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary, | - | ||||||||||||||||||||||||
| 2475 | {How to Create Qt Plugins} | - | ||||||||||||||||||||||||
| 2476 | */ | - | ||||||||||||||||||||||||
| 2477 | QStringList QCoreApplication::libraryPaths() | - | ||||||||||||||||||||||||
| 2478 | { | - | ||||||||||||||||||||||||
| 2479 | QMutexLocker locker(libraryPathMutex()); | - | ||||||||||||||||||||||||
| 2480 | - | |||||||||||||||||||||||||
| 2481 | if (coreappdata()->manual_libpaths) | - | ||||||||||||||||||||||||
| 2482 | return *(coreappdata()->manual_libpaths); | - | ||||||||||||||||||||||||
| 2483 | - | |||||||||||||||||||||||||
| 2484 | if (!coreappdata()->app_libpaths) { | - | ||||||||||||||||||||||||
| 2485 | QStringList *app_libpaths = new QStringList; | - | ||||||||||||||||||||||||
| 2486 | coreappdata()->app_libpaths.reset(app_libpaths); | - | ||||||||||||||||||||||||
| 2487 | - | |||||||||||||||||||||||||
| 2488 | const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH"); | - | ||||||||||||||||||||||||
| 2489 | if (!libPathEnv.isEmpty()) { | - | ||||||||||||||||||||||||
| 2490 | QStringList paths = QFile::decodeName(libPathEnv).split(QDir::listSeparator(), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
| 2491 | for (QStringList::const_iterator it = paths.constBegin(); it != paths.constEnd(); ++it) { | - | ||||||||||||||||||||||||
| 2492 | QString canonicalPath = QDir(*it).canonicalPath(); | - | ||||||||||||||||||||||||
| 2493 | if (!canonicalPath.isEmpty() | - | ||||||||||||||||||||||||
| 2494 | && !app_libpaths->contains(canonicalPath)) { | - | ||||||||||||||||||||||||
| 2495 | app_libpaths->append(canonicalPath); | - | ||||||||||||||||||||||||
| 2496 | } | - | ||||||||||||||||||||||||
| 2497 | } | - | ||||||||||||||||||||||||
| 2498 | } | - | ||||||||||||||||||||||||
| 2499 | - | |||||||||||||||||||||||||
| 2500 | QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); | - | ||||||||||||||||||||||||
| 2501 | if (QFile::exists(installPathPlugins)) { | - | ||||||||||||||||||||||||
| 2502 | // Make sure we convert from backslashes to slashes. | - | ||||||||||||||||||||||||
| 2503 | installPathPlugins = QDir(installPathPlugins).canonicalPath(); | - | ||||||||||||||||||||||||
| 2504 | if (!app_libpaths->contains(installPathPlugins)) | - | ||||||||||||||||||||||||
| 2505 | app_libpaths->append(installPathPlugins); | - | ||||||||||||||||||||||||
| 2506 | } | - | ||||||||||||||||||||||||
| 2507 | - | |||||||||||||||||||||||||
| 2508 | // If QCoreApplication is not yet instantiated, | - | ||||||||||||||||||||||||
| 2509 | // make sure we add the application path when we construct the QCoreApplication | - | ||||||||||||||||||||||||
| 2510 | if (self) self->d_func()->appendApplicationPathToLibraryPaths(); | - | ||||||||||||||||||||||||
| 2511 | } | - | ||||||||||||||||||||||||
| 2512 | return *(coreappdata()->app_libpaths); | - | ||||||||||||||||||||||||
| 2513 | } | - | ||||||||||||||||||||||||
| 2514 | - | |||||||||||||||||||||||||
| 2515 | - | |||||||||||||||||||||||||
| 2516 | - | |||||||||||||||||||||||||
| 2517 | /*! | - | ||||||||||||||||||||||||
| 2518 | - | |||||||||||||||||||||||||
| 2519 | Sets the list of directories to search when loading libraries to | - | ||||||||||||||||||||||||
| 2520 | \a paths. All existing paths will be deleted and the path list | - | ||||||||||||||||||||||||
| 2521 | will consist of the paths given in \a paths. | - | ||||||||||||||||||||||||
| 2522 | - | |||||||||||||||||||||||||
| 2523 | The library paths are reset to the default when an instance of | - | ||||||||||||||||||||||||
| 2524 | QCoreApplication is destructed. | - | ||||||||||||||||||||||||
| 2525 | - | |||||||||||||||||||||||||
| 2526 | \sa libraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary | - | ||||||||||||||||||||||||
| 2527 | */ | - | ||||||||||||||||||||||||
| 2528 | void QCoreApplication::setLibraryPaths(const QStringList &paths) | - | ||||||||||||||||||||||||
| 2529 | { | - | ||||||||||||||||||||||||
| 2530 | QMutexLocker locker(libraryPathMutex()); | - | ||||||||||||||||||||||||
| 2531 | - | |||||||||||||||||||||||||
| 2532 | // setLibraryPaths() is considered a "remove everything and then add some new ones" operation. | - | ||||||||||||||||||||||||
| 2533 | // When the application is constructed it should still amend the paths. So we keep the originals | - | ||||||||||||||||||||||||
| 2534 | // around, and even create them if they don't exist, yet. | - | ||||||||||||||||||||||||
| 2535 | if (!coreappdata()->app_libpaths) | - | ||||||||||||||||||||||||
| 2536 | libraryPaths(); | - | ||||||||||||||||||||||||
| 2537 | - | |||||||||||||||||||||||||
| 2538 | if (coreappdata()->manual_libpaths) | - | ||||||||||||||||||||||||
| 2539 | *(coreappdata()->manual_libpaths) = paths; | - | ||||||||||||||||||||||||
| 2540 | else | - | ||||||||||||||||||||||||
| 2541 | coreappdata()->manual_libpaths.reset(new QStringList(paths)); | - | ||||||||||||||||||||||||
| 2542 | - | |||||||||||||||||||||||||
| 2543 | locker.unlock(); | - | ||||||||||||||||||||||||
| 2544 | QFactoryLoader::refreshAll(); | - | ||||||||||||||||||||||||
| 2545 | } | - | ||||||||||||||||||||||||
| 2546 | - | |||||||||||||||||||||||||
| 2547 | /*! | - | ||||||||||||||||||||||||
| 2548 | Prepends \a path to the beginning of the library path list, ensuring that | - | ||||||||||||||||||||||||
| 2549 | it is searched for libraries first. If \a path is empty or already in the | - | ||||||||||||||||||||||||
| 2550 | path list, the path list is not changed. | - | ||||||||||||||||||||||||
| 2551 | - | |||||||||||||||||||||||||
| 2552 | The default path list consists of a single entry, the installation | - | ||||||||||||||||||||||||
| 2553 | directory for plugins. The default installation directory for plugins | - | ||||||||||||||||||||||||
| 2554 | is \c INSTALL/plugins, where \c INSTALL is the directory where Qt was | - | ||||||||||||||||||||||||
| 2555 | installed. | - | ||||||||||||||||||||||||
| 2556 | - | |||||||||||||||||||||||||
| 2557 | The library paths are reset to the default when an instance of | - | ||||||||||||||||||||||||
| 2558 | QCoreApplication is destructed. | - | ||||||||||||||||||||||||
| 2559 | - | |||||||||||||||||||||||||
| 2560 | \sa removeLibraryPath(), libraryPaths(), setLibraryPaths() | - | ||||||||||||||||||||||||
| 2561 | */ | - | ||||||||||||||||||||||||
| 2562 | void QCoreApplication::addLibraryPath(const QString &path) | - | ||||||||||||||||||||||||
| 2563 | { | - | ||||||||||||||||||||||||
| 2564 | if (path.isEmpty()) | - | ||||||||||||||||||||||||
| 2565 | return; | - | ||||||||||||||||||||||||
| 2566 | - | |||||||||||||||||||||||||
| 2567 | QString canonicalPath = QDir(path).canonicalPath(); | - | ||||||||||||||||||||||||
| 2568 | if (canonicalPath.isEmpty()) | - | ||||||||||||||||||||||||
| 2569 | return; | - | ||||||||||||||||||||||||
| 2570 | - | |||||||||||||||||||||||||
| 2571 | QMutexLocker locker(libraryPathMutex()); | - | ||||||||||||||||||||||||
| 2572 | - | |||||||||||||||||||||||||
| 2573 | QStringList *libpaths = coreappdata()->manual_libpaths.data(); | - | ||||||||||||||||||||||||
| 2574 | if (libpaths) { | - | ||||||||||||||||||||||||
| 2575 | if (libpaths->contains(canonicalPath)) | - | ||||||||||||||||||||||||
| 2576 | return; | - | ||||||||||||||||||||||||
| 2577 | } else { | - | ||||||||||||||||||||||||
| 2578 | // make sure that library paths are initialized | - | ||||||||||||||||||||||||
| 2579 | libraryPaths(); | - | ||||||||||||||||||||||||
| 2580 | QStringList *app_libpaths = coreappdata()->app_libpaths.data(); | - | ||||||||||||||||||||||||
| 2581 | if (app_libpaths->contains(canonicalPath)) | - | ||||||||||||||||||||||||
| 2582 | return; | - | ||||||||||||||||||||||||
| 2583 | - | |||||||||||||||||||||||||
| 2584 | coreappdata()->manual_libpaths.reset(libpaths = new QStringList(*app_libpaths)); | - | ||||||||||||||||||||||||
| 2585 | } | - | ||||||||||||||||||||||||
| 2586 | - | |||||||||||||||||||||||||
| 2587 | libpaths->prepend(canonicalPath); | - | ||||||||||||||||||||||||
| 2588 | locker.unlock(); | - | ||||||||||||||||||||||||
| 2589 | QFactoryLoader::refreshAll(); | - | ||||||||||||||||||||||||
| 2590 | } | - | ||||||||||||||||||||||||
| 2591 | - | |||||||||||||||||||||||||
| 2592 | /*! | - | ||||||||||||||||||||||||
| 2593 | Removes \a path from the library path list. If \a path is empty or not | - | ||||||||||||||||||||||||
| 2594 | in the path list, the list is not changed. | - | ||||||||||||||||||||||||
| 2595 | - | |||||||||||||||||||||||||
| 2596 | The library paths are reset to the default when an instance of | - | ||||||||||||||||||||||||
| 2597 | QCoreApplication is destructed. | - | ||||||||||||||||||||||||
| 2598 | - | |||||||||||||||||||||||||
| 2599 | \sa addLibraryPath(), libraryPaths(), setLibraryPaths() | - | ||||||||||||||||||||||||
| 2600 | */ | - | ||||||||||||||||||||||||
| 2601 | void QCoreApplication::removeLibraryPath(const QString &path) | - | ||||||||||||||||||||||||
| 2602 | { | - | ||||||||||||||||||||||||
| 2603 | if (path.isEmpty()) | - | ||||||||||||||||||||||||
| 2604 | return; | - | ||||||||||||||||||||||||
| 2605 | - | |||||||||||||||||||||||||
| 2606 | QString canonicalPath = QDir(path).canonicalPath(); | - | ||||||||||||||||||||||||
| 2607 | if (canonicalPath.isEmpty()) | - | ||||||||||||||||||||||||
| 2608 | return; | - | ||||||||||||||||||||||||
| 2609 | - | |||||||||||||||||||||||||
| 2610 | QMutexLocker locker(libraryPathMutex()); | - | ||||||||||||||||||||||||
| 2611 | - | |||||||||||||||||||||||||
| 2612 | QStringList *libpaths = coreappdata()->manual_libpaths.data(); | - | ||||||||||||||||||||||||
| 2613 | if (libpaths) { | - | ||||||||||||||||||||||||
| 2614 | if (libpaths->removeAll(canonicalPath) == 0) | - | ||||||||||||||||||||||||
| 2615 | return; | - | ||||||||||||||||||||||||
| 2616 | } else { | - | ||||||||||||||||||||||||
| 2617 | // make sure that library paths is initialized | - | ||||||||||||||||||||||||
| 2618 | libraryPaths(); | - | ||||||||||||||||||||||||
| 2619 | QStringList *app_libpaths = coreappdata()->app_libpaths.data(); | - | ||||||||||||||||||||||||
| 2620 | if (!app_libpaths->contains(canonicalPath)) | - | ||||||||||||||||||||||||
| 2621 | return; | - | ||||||||||||||||||||||||
| 2622 | - | |||||||||||||||||||||||||
| 2623 | coreappdata()->manual_libpaths.reset(libpaths = new QStringList(*app_libpaths)); | - | ||||||||||||||||||||||||
| 2624 | libpaths->removeAll(canonicalPath); | - | ||||||||||||||||||||||||
| 2625 | } | - | ||||||||||||||||||||||||
| 2626 | - | |||||||||||||||||||||||||
| 2627 | locker.unlock(); | - | ||||||||||||||||||||||||
| 2628 | QFactoryLoader::refreshAll(); | - | ||||||||||||||||||||||||
| 2629 | } | - | ||||||||||||||||||||||||
| 2630 | - | |||||||||||||||||||||||||
| 2631 | #endif //QT_NO_LIBRARY | - | ||||||||||||||||||||||||
| 2632 | - | |||||||||||||||||||||||||
| 2633 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2634 | - | |||||||||||||||||||||||||
| 2635 | /*! | - | ||||||||||||||||||||||||
| 2636 | Installs an event filter \a filterObj for all native events | - | ||||||||||||||||||||||||
| 2637 | received by the application in the main thread. | - | ||||||||||||||||||||||||
| 2638 | - | |||||||||||||||||||||||||
| 2639 | The event filter \a filterObj receives events via its \l {QAbstractNativeEventFilter::}{nativeEventFilter()} | - | ||||||||||||||||||||||||
| 2640 | function, which is called for all native events received in the main thread. | - | ||||||||||||||||||||||||
| 2641 | - | |||||||||||||||||||||||||
| 2642 | The QAbstractNativeEventFilter::nativeEventFilter() function should | - | ||||||||||||||||||||||||
| 2643 | return true if the event should be filtered, i.e. stopped. It should | - | ||||||||||||||||||||||||
| 2644 | return false to allow normal Qt processing to continue: the native | - | ||||||||||||||||||||||||
| 2645 | event can then be translated into a QEvent and handled by the standard | - | ||||||||||||||||||||||||
| 2646 | Qt \l{QEvent} {event} filtering, e.g. QObject::installEventFilter(). | - | ||||||||||||||||||||||||
| 2647 | - | |||||||||||||||||||||||||
| 2648 | If multiple event filters are installed, the filter that was | - | ||||||||||||||||||||||||
| 2649 | installed last is activated first. | - | ||||||||||||||||||||||||
| 2650 | - | |||||||||||||||||||||||||
| 2651 | \note The filter function set here receives native messages, | - | ||||||||||||||||||||||||
| 2652 | i.e. MSG or XCB event structs. | - | ||||||||||||||||||||||||
| 2653 | - | |||||||||||||||||||||||||
| 2654 | \note Native event filters will be disabled in the application when the | - | ||||||||||||||||||||||||
| 2655 | Qt::AA_PluginApplication attribute is set. | - | ||||||||||||||||||||||||
| 2656 | - | |||||||||||||||||||||||||
| 2657 | For maximum portability, you should always try to use QEvent | - | ||||||||||||||||||||||||
| 2658 | and QObject::installEventFilter() whenever possible. | - | ||||||||||||||||||||||||
| 2659 | - | |||||||||||||||||||||||||
| 2660 | \sa QObject::installEventFilter() | - | ||||||||||||||||||||||||
| 2661 | - | |||||||||||||||||||||||||
| 2662 | \since 5.0 | - | ||||||||||||||||||||||||
| 2663 | */ | - | ||||||||||||||||||||||||
| 2664 | void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filterObj) | - | ||||||||||||||||||||||||
| 2665 | { | - | ||||||||||||||||||||||||
| 2666 | if (QCoreApplication::testAttribute(Qt::AA_MacPluginApplicationAA_PluginApplication)) {
| 0-1 | ||||||||||||||||||||||||
| 2667 | qWarning("Native event filters are not applied when the Qt::AA_MacPluginApplicationAA_PluginApplication attribute is set"); | - | ||||||||||||||||||||||||
| 2668 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2669 | } | - | ||||||||||||||||||||||||
| 2670 | - | |||||||||||||||||||||||||
| 2671 | QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(QCoreApplicationPrivate::theMainThread); | - | ||||||||||||||||||||||||
| 2672 | if (!filterObj || !eventDispatcher)
| 0-1 | ||||||||||||||||||||||||
| 2673 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2674 | eventDispatcher->installNativeEventFilter(filterObj); | - | ||||||||||||||||||||||||
| 2675 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 2676 | - | |||||||||||||||||||||||||
| 2677 | /*! | - | ||||||||||||||||||||||||
| 2678 | Removes an event \a filterObject from this object. The | - | ||||||||||||||||||||||||
| 2679 | request is ignored if such an event filter has not been installed. | - | ||||||||||||||||||||||||
| 2680 | - | |||||||||||||||||||||||||
| 2681 | All event filters for this object are automatically removed when | - | ||||||||||||||||||||||||
| 2682 | this object is destroyed. | - | ||||||||||||||||||||||||
| 2683 | - | |||||||||||||||||||||||||
| 2684 | It is always safe to remove an event filter, even during event | - | ||||||||||||||||||||||||
| 2685 | filter activation (i.e. from the nativeEventFilter() function). | - | ||||||||||||||||||||||||
| 2686 | - | |||||||||||||||||||||||||
| 2687 | \sa installNativeEventFilter() | - | ||||||||||||||||||||||||
| 2688 | \since 5.0 | - | ||||||||||||||||||||||||
| 2689 | */ | - | ||||||||||||||||||||||||
| 2690 | void QCoreApplication::removeNativeEventFilter(QAbstractNativeEventFilter *filterObject) | - | ||||||||||||||||||||||||
| 2691 | { | - | ||||||||||||||||||||||||
| 2692 | QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(); | - | ||||||||||||||||||||||||
| 2693 | if (!filterObject || !eventDispatcher) | - | ||||||||||||||||||||||||
| 2694 | return; | - | ||||||||||||||||||||||||
| 2695 | eventDispatcher->removeNativeEventFilter(filterObject); | - | ||||||||||||||||||||||||
| 2696 | } | - | ||||||||||||||||||||||||
| 2697 | - | |||||||||||||||||||||||||
| 2698 | /*! | - | ||||||||||||||||||||||||
| 2699 | \deprecated | - | ||||||||||||||||||||||||
| 2700 | - | |||||||||||||||||||||||||
| 2701 | This function returns \c true if there are pending events; otherwise | - | ||||||||||||||||||||||||
| 2702 | returns \c false. Pending events can be either from the window | - | ||||||||||||||||||||||||
| 2703 | system or posted events using postEvent(). | - | ||||||||||||||||||||||||
| 2704 | - | |||||||||||||||||||||||||
| 2705 | \note this function is not thread-safe. It may only be called in the main | - | ||||||||||||||||||||||||
| 2706 | thread and only if there are no other threads running in the application | - | ||||||||||||||||||||||||
| 2707 | (including threads Qt starts for its own purposes). | - | ||||||||||||||||||||||||
| 2708 | - | |||||||||||||||||||||||||
| 2709 | \sa QAbstractEventDispatcher::hasPendingEvents() | - | ||||||||||||||||||||||||
| 2710 | */ | - | ||||||||||||||||||||||||
| 2711 | #if QT_DEPRECATED_SINCE(5, 3) | - | ||||||||||||||||||||||||
| 2712 | bool QCoreApplication::hasPendingEvents() | - | ||||||||||||||||||||||||
| 2713 | { | - | ||||||||||||||||||||||||
| 2714 | QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(); | - | ||||||||||||||||||||||||
| 2715 | if (eventDispatcher) | - | ||||||||||||||||||||||||
| 2716 | return eventDispatcher->hasPendingEvents(); | - | ||||||||||||||||||||||||
| 2717 | return false; | - | ||||||||||||||||||||||||
| 2718 | } | - | ||||||||||||||||||||||||
| 2719 | #endif | - | ||||||||||||||||||||||||
| 2720 | - | |||||||||||||||||||||||||
| 2721 | /*! | - | ||||||||||||||||||||||||
| 2722 | Returns a pointer to the event dispatcher object for the main thread. If no | - | ||||||||||||||||||||||||
| 2723 | event dispatcher exists for the thread, this function returns 0. | - | ||||||||||||||||||||||||
| 2724 | */ | - | ||||||||||||||||||||||||
| 2725 | QAbstractEventDispatcher *QCoreApplication::eventDispatcher() | - | ||||||||||||||||||||||||
| 2726 | { | - | ||||||||||||||||||||||||
| 2727 | if (QCoreApplicationPrivate::theMainThread) | - | ||||||||||||||||||||||||
| 2728 | return QCoreApplicationPrivate::theMainThread.load()->eventDispatcher(); | - | ||||||||||||||||||||||||
| 2729 | return 0; | - | ||||||||||||||||||||||||
| 2730 | } | - | ||||||||||||||||||||||||
| 2731 | - | |||||||||||||||||||||||||
| 2732 | /*! | - | ||||||||||||||||||||||||
| 2733 | Sets the event dispatcher for the main thread to \a eventDispatcher. This | - | ||||||||||||||||||||||||
| 2734 | is only possible as long as there is no event dispatcher installed yet. That | - | ||||||||||||||||||||||||
| 2735 | is, before QCoreApplication has been instantiated. This method takes | - | ||||||||||||||||||||||||
| 2736 | ownership of the object. | - | ||||||||||||||||||||||||
| 2737 | */ | - | ||||||||||||||||||||||||
| 2738 | void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher) | - | ||||||||||||||||||||||||
| 2739 | { | - | ||||||||||||||||||||||||
| 2740 | QThread *mainThread = QCoreApplicationPrivate::theMainThread; | - | ||||||||||||||||||||||||
| 2741 | if (!mainThread) | - | ||||||||||||||||||||||||
| 2742 | mainThread = QThread::currentThread(); // will also setup theMainThread | - | ||||||||||||||||||||||||
| 2743 | mainThread->setEventDispatcher(eventDispatcher); | - | ||||||||||||||||||||||||
| 2744 | } | - | ||||||||||||||||||||||||
| 2745 | - | |||||||||||||||||||||||||
| 2746 | #endif // QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 2747 | - | |||||||||||||||||||||||||
| 2748 | /*! | - | ||||||||||||||||||||||||
| 2749 | \macro Q_COREAPP_STARTUP_FUNCTION(QtStartUpFunction ptr) | - | ||||||||||||||||||||||||
| 2750 | \since 5.1 | - | ||||||||||||||||||||||||
| 2751 | \relates QCoreApplication | - | ||||||||||||||||||||||||
| 2752 | \reentrant | - | ||||||||||||||||||||||||
| 2753 | - | |||||||||||||||||||||||||
| 2754 | Adds a global function that will be called from the QCoreApplication | - | ||||||||||||||||||||||||
| 2755 | constructor. This macro is normally used to initialize libraries | - | ||||||||||||||||||||||||
| 2756 | for program-wide functionality, without requiring the application to | - | ||||||||||||||||||||||||
| 2757 | call into the library for initialization. | - | ||||||||||||||||||||||||
| 2758 | - | |||||||||||||||||||||||||
| 2759 | The function specified by \a ptr should take no arguments and should | - | ||||||||||||||||||||||||
| 2760 | return nothing. For example: | - | ||||||||||||||||||||||||
| 2761 | - | |||||||||||||||||||||||||
| 2762 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 3 | - | ||||||||||||||||||||||||
| 2763 | - | |||||||||||||||||||||||||
| 2764 | Note that the startup function will run at the end of the QCoreApplication constructor, | - | ||||||||||||||||||||||||
| 2765 | before any GUI initialization. If GUI code is required in the function, | - | ||||||||||||||||||||||||
| 2766 | use a timer (or a queued invocation) to perform the initialization later on, | - | ||||||||||||||||||||||||
| 2767 | from the event loop. | - | ||||||||||||||||||||||||
| 2768 | - | |||||||||||||||||||||||||
| 2769 | If QCoreApplication is deleted and another QCoreApplication is created, | - | ||||||||||||||||||||||||
| 2770 | the startup function will be invoked again. | - | ||||||||||||||||||||||||
| 2771 | */ | - | ||||||||||||||||||||||||
| 2772 | - | |||||||||||||||||||||||||
| 2773 | /*! | - | ||||||||||||||||||||||||
| 2774 | \fn void qAddPostRoutine(QtCleanUpFunction ptr) | - | ||||||||||||||||||||||||
| 2775 | \relates QCoreApplication | - | ||||||||||||||||||||||||
| 2776 | - | |||||||||||||||||||||||||
| 2777 | Adds a global routine that will be called from the QCoreApplication | - | ||||||||||||||||||||||||
| 2778 | destructor. This function is normally used to add cleanup routines | - | ||||||||||||||||||||||||
| 2779 | for program-wide functionality. | - | ||||||||||||||||||||||||
| 2780 | - | |||||||||||||||||||||||||
| 2781 | The cleanup routines are called in the reverse order of their addition. | - | ||||||||||||||||||||||||
| 2782 | - | |||||||||||||||||||||||||
| 2783 | The function specified by \a ptr should take no arguments and should | - | ||||||||||||||||||||||||
| 2784 | return nothing. For example: | - | ||||||||||||||||||||||||
| 2785 | - | |||||||||||||||||||||||||
| 2786 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 4 | - | ||||||||||||||||||||||||
| 2787 | - | |||||||||||||||||||||||||
| 2788 | Note that for an application- or module-wide cleanup, qaddPostRoutine() | - | ||||||||||||||||||||||||
| 2789 | is often not suitable. For example, if the program is split into dynamically | - | ||||||||||||||||||||||||
| 2790 | loaded modules, the relevant module may be unloaded long before the | - | ||||||||||||||||||||||||
| 2791 | QCoreApplication destructor is called. In such cases, if using qaddPostRoutine() | - | ||||||||||||||||||||||||
| 2792 | is still desirable, qRemovePostRoutine() can be used to prevent a routine | - | ||||||||||||||||||||||||
| 2793 | from being called by the QCoreApplication destructor. For example, if that | - | ||||||||||||||||||||||||
| 2794 | routine was called before the module was unloaded. | - | ||||||||||||||||||||||||
| 2795 | - | |||||||||||||||||||||||||
| 2796 | For modules and libraries, using a reference-counted | - | ||||||||||||||||||||||||
| 2797 | initialization manager or Qt's parent-child deletion mechanism may | - | ||||||||||||||||||||||||
| 2798 | be better. Here is an example of a private class that uses the | - | ||||||||||||||||||||||||
| 2799 | parent-child mechanism to call a cleanup function at the right | - | ||||||||||||||||||||||||
| 2800 | time: | - | ||||||||||||||||||||||||
| 2801 | - | |||||||||||||||||||||||||
| 2802 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 5 | - | ||||||||||||||||||||||||
| 2803 | - | |||||||||||||||||||||||||
| 2804 | By selecting the right parent object, this can often be made to | - | ||||||||||||||||||||||||
| 2805 | clean up the module's data at the right moment. | - | ||||||||||||||||||||||||
| 2806 | - | |||||||||||||||||||||||||
| 2807 | \sa qRemovePostRoutine() | - | ||||||||||||||||||||||||
| 2808 | */ | - | ||||||||||||||||||||||||
| 2809 | - | |||||||||||||||||||||||||
| 2810 | /*! | - | ||||||||||||||||||||||||
| 2811 | \fn void qRemovePostRoutine(QtCleanUpFunction ptr) | - | ||||||||||||||||||||||||
| 2812 | \relates QCoreApplication | - | ||||||||||||||||||||||||
| 2813 | \since 5.3 | - | ||||||||||||||||||||||||
| 2814 | - | |||||||||||||||||||||||||
| 2815 | Removes the cleanup routine specified by \a ptr from the list of | - | ||||||||||||||||||||||||
| 2816 | routines called by the QCoreApplication destructor. The routine | - | ||||||||||||||||||||||||
| 2817 | must have been previously added to the list by a call to | - | ||||||||||||||||||||||||
| 2818 | qAddPostRoutine(), otherwise this function has no effect. | - | ||||||||||||||||||||||||
| 2819 | - | |||||||||||||||||||||||||
| 2820 | \sa qAddPostRoutine() | - | ||||||||||||||||||||||||
| 2821 | */ | - | ||||||||||||||||||||||||
| 2822 | - | |||||||||||||||||||||||||
| 2823 | /*! | - | ||||||||||||||||||||||||
| 2824 | \macro Q_DECLARE_TR_FUNCTIONS(context) | - | ||||||||||||||||||||||||
| 2825 | \relates QCoreApplication | - | ||||||||||||||||||||||||
| 2826 | - | |||||||||||||||||||||||||
| 2827 | The Q_DECLARE_TR_FUNCTIONS() macro declares and implements two | - | ||||||||||||||||||||||||
| 2828 | translation functions, \c tr() and \c trUtf8(), with these | - | ||||||||||||||||||||||||
| 2829 | signatures: | - | ||||||||||||||||||||||||
| 2830 | - | |||||||||||||||||||||||||
| 2831 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 6 | - | ||||||||||||||||||||||||
| 2832 | - | |||||||||||||||||||||||||
| 2833 | This macro is useful if you want to use QObject::tr() or | - | ||||||||||||||||||||||||
| 2834 | QObject::trUtf8() in classes that don't inherit from QObject. | - | ||||||||||||||||||||||||
| 2835 | - | |||||||||||||||||||||||||
| 2836 | Q_DECLARE_TR_FUNCTIONS() must appear at the very top of the | - | ||||||||||||||||||||||||
| 2837 | class definition (before the first \c{public:} or \c{protected:}). | - | ||||||||||||||||||||||||
| 2838 | For example: | - | ||||||||||||||||||||||||
| 2839 | - | |||||||||||||||||||||||||
| 2840 | \snippet code/src_corelib_kernel_qcoreapplication.cpp 7 | - | ||||||||||||||||||||||||
| 2841 | - | |||||||||||||||||||||||||
| 2842 | The \a context parameter is normally the class name, but it can | - | ||||||||||||||||||||||||
| 2843 | be any text. | - | ||||||||||||||||||||||||
| 2844 | - | |||||||||||||||||||||||||
| 2845 | \sa Q_OBJECT, QObject::tr(), QObject::trUtf8() | - | ||||||||||||||||||||||||
| 2846 | */ | - | ||||||||||||||||||||||||
| 2847 | - | |||||||||||||||||||||||||
| 2848 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |