📄 qcoreapplication.cpp
字号:
if (!data->postEventList.recursion) { // truncate list data->postEventList.erase(data->postEventList.begin() + j, data->postEventList.end()); }}/*! Removes \a event from the queue of posted events, and emits a warning message if appropriate. \warning This function can be \e really slow. Avoid using it, if possible. \threadsafe*/void QCoreApplicationPrivate::removePostedEvent(QEvent * event){ if (!event || !event->posted) return; QThreadData *data = QThreadData::current(); QMutexLocker locker(&data->postEventList.mutex); if (data->postEventList.size() == 0) {#if defined(QT_DEBUG) qDebug("QCoreApplication::removePostedEvent: Internal error: %p %d is posted", (void*)event, event->type()); return;#endif } for (int i = 0; i < data->postEventList.size(); ++i) { const QPostEvent & pe = data->postEventList.at(i); if (pe.event == event) {#ifndef QT_NO_DEBUG qWarning("QCoreApplication::removePostedEvent: Event of type %d deleted while posted to %s %s", event->type(), pe.receiver->metaObject()->className(), pe.receiver->objectName().toLocal8Bit().data());#endif --pe.receiver->d_func()->postedEvents; pe.event->posted = false; delete pe.event; const_cast<QPostEvent &>(pe).event = 0; return; } }}/*!\reimp*/bool QCoreApplication::event(QEvent *e){ if (e->type() == QEvent::Quit) { quit(); return true; } return QObject::event(e);}/*! \enum QCoreApplication::Encoding This enum type defines the 8-bit encoding of character string arguments to translate(): \value CodecForTr The encoding specified by QTextCodec::codecForTr() (Latin-1 if none has been set). \value UnicodeUTF8 UTF-8. \value DefaultCodec (Obsolete) Use CodecForTr instead. \sa QObject::tr(), QObject::trUtf8(), QString::fromUtf8()*//*! Tells the application to exit with return code 0 (success). Equivalent to calling QCoreApplication::exit(0). It's common to connect the QApplication::lastWindowClosed() signal to quit(), and you also often connect e.g. QAbstractButton::clicked() or signals in QAction, QMenu, or QMenuBar to it. Example: \code QPushButton *quitButton = new QPushButton("Quit"); connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit())); \endcode \sa exit(), aboutToQuit(), QApplication::lastWindowClosed()*/void QCoreApplication::quit(){ exit(0);}/*! \fn void QCoreApplication::aboutToQuit() This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session. The signal is particularly useful if your application has to do some last-second cleanup. Note that no user interaction is possible in this state. \sa quit()*/#ifndef QT_NO_TRANSLATION/*! Adds the translation file \a translationFile to the list of translation files to be used for translations. Multiple translation files can be installed. Translations are searched for in the last installed translation file on, back to the first installed translation file. The search stops as soon as a matching translation is found. \sa removeTranslator() translate() QTranslator::load()*/void QCoreApplication::installTranslator(QTranslator *translationFile){ if (!translationFile) return; if (!QCoreApplicationPrivate::checkInstance("installTranslator")) return; QCoreApplicationPrivate *d = self->d_func(); d->translators.prepend(translationFile);#ifndef QT_NO_TRANSLATION_BUILDER if (translationFile->isEmpty()) return;#endif QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev);}/*! Removes the translation file \a translationFile from the list of translation files used by this application. (It does not delete the translation file from the file system.) \sa installTranslator() translate(), QObject::tr()*/void QCoreApplication::removeTranslator(QTranslator *translationFile){ if (!translationFile) return; if (!QCoreApplicationPrivate::checkInstance("removeTranslator")) return; QCoreApplicationPrivate *d = self->d_func(); if (d->translators.removeAll(translationFile) && !self->closingDown()) { QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev); }}/*! \overload*/QString QCoreApplication::translate(const char *context, const char *sourceText, const char *comment, Encoding encoding){ return translate(context, sourceText, comment, encoding, -1);}/*! \reentrant Returns the translation text for \a sourceText, by querying the installed translation files. The translation files are searched from the most recently installed file back to the first installed file. QObject::tr() and QObject::trUtf8() provide this functionality more conveniently. \a context is typically a class name (e.g., "MyDialog") and \a sourceText is either English text or a short identifying text. \a comment is a disambiguating comment, for when the same \a sourceText is used in different roles within the same context. By default, it is null. \a encoding indicates the 8-bit encoding of character stings See the \l QTranslator documentation for more information about contexts and comments. \a n is used in conjunction with \c %n to support plural forms. See QObject::tr() for details. If none of the translation files contain a translation for \a sourceText in \a context, this function returns a QString equivalent of \a sourceText. The encoding of \a sourceText is specified by \e encoding; it defaults to CodecForTr. This function is not virtual. You can use alternative translation techniques by subclassing \l QTranslator. \warning This method is reentrant only if all translators are installed \e before calling this method. Installing or removing translators while performing translations is not supported. Doing so will most likely result in crashes or other undesirable behavior. \sa QObject::tr() installTranslator() QTextCodec::codecForTr()*/QString QCoreApplication::translate(const char *context, const char *sourceText, const char *comment, Encoding encoding, int n){ QString result; if (!sourceText) return result; if (self && !self->d_func()->translators.isEmpty()) { QList<QTranslator*>::ConstIterator it; QTranslator *translationFile; for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) { translationFile = *it; result = translationFile->translate(context, sourceText, comment, n); if (!result.isEmpty()) break; } } if (result.isEmpty()) {#ifdef QT_NO_TEXTCODEC Q_UNUSED(encoding)#else if (encoding == UnicodeUTF8) result = QString::fromUtf8(sourceText); else if (QTextCodec::codecForTr() != 0) result = QTextCodec::codecForTr()->toUnicode(sourceText); else#endif result = QString::fromLatin1(sourceText); } if (n >= 0) { int percentPos = -1; while ((percentPos = result.indexOf(QLatin1Char('%'), percentPos + 1)) != -1) { int len = 1; QString fmt(QLatin1String("%1")); if (result.mid(percentPos + len, 1).startsWith(QLatin1Char('L'))) { ++len; fmt = QLatin1String("%L1"); } if (result.mid(percentPos + len, 1).startsWith(QLatin1Char('n'))) { ++len; result.replace(percentPos, len, fmt.arg(n)); } } } return result;}bool QCoreApplicationPrivate::isTranslatorInstalled(QTranslator *translator){ return QCoreApplication::self && QCoreApplication::self->d_func()->translators.contains(translator);}#endif //QT_NO_TRANSLATE/*! Returns the directory that contains the application executable. For example, if you have installed Qt in the \c{C:\Trolltech\Qt} directory, and you run the \c{regexp} example, this function will return "C:/Trolltech/Qt/examples/tools/regexp". On Mac OS X this will point to the directory actually containing the executable, which may be inside of an application bundle (if the application is bundled). \warning On Unix, this function assumes that argv[0] contains the file name of the executable (which it normally does). It also assumes that the current directory hasn't been changed by the application. \sa applicationFilePath()*/QString QCoreApplication::applicationDirPath(){ if (!self) { qWarning("QCoreApplication::applicationDirPath: Please instantiate the QApplication object first"); return QString(); } return QFileInfo(applicationFilePath()).path();}/*! Returns the file path of the application executable. For example, if you have installed Qt in the \c{/usr/local/qt} directory, and you run the \c{regexp} example, this function will return "/usr/local/qt/examples/tools/regexp/regexp". \warning On Unix, this function assumes that argv[0] contains the file name of the executable (which it normally does). It also assumes that the current directory hasn't been changed by the application. \sa applicationDirPath()*/QString QCoreApplication::applicationFilePath(){ if (!self) { qWarning("QCoreApplication::applicationFilePath: Please instantiate the QApplication object first"); return QString(); }#if defined( Q_WS_WIN ) QFileInfo filePath; QT_WA({ wchar_t module_name[256]; GetModuleFileNameW(0, module_name, sizeof(module_name) / sizeof(wchar_t)); filePath = QString::fromUtf16((ushort *)module_name); }, { char module_name[256]; GetModuleFileNameA(0, module_name, sizeof(module_name)); filePath = QString::fromLocal8Bit(module_name); }); return filePath.filePath();#elif defined(Q_WS_MAC) QString qAppFileName_str = qAppFileName(); if(!qAppFileName_str.isEmpty()) { QFileInfo fi(qAppFileName_str); return fi.exists() ? fi.canonicalFilePath() : QString(); }#endif#if defined( Q_OS_UNIX )# ifdef Q_OS_LINUX // Try looking for a /proc/<pid>/exe symlink first which points to // the absolute path of the executable QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(getpid())); if (pfi.exists() && pfi.isSymLink()) return pfi.canonicalFilePath();# endif QString argv0 = QFile::decodeName(QByteArray(argv()[0])); QString absPath; if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { /* If argv0 starts with a slash, it is already an absolute file path. */ absPath = argv0; } else if (argv0.contains(QLatin1Char('/'))) { /* If argv0 contains one or more slashes, it is a file path relative to the current directory. */ absPath = QDir::current().absoluteFilePath(argv0); } else { /* Otherwise, the file path has to be determined using the PATH environment variable. */ QByteArray pEnv = qgetenv("PATH"); QDir currentDir = QDir::current(); QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":")); for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) { if ((*p).isEmpty()) continue; QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0); QFileInfo candidate_fi(candidate); if (candidate_fi.exists() && !candidate_fi.isDir()) { absPath = candidate; break; } } } absPath = QDir::cleanPath(absPath); QFileInfo fi(absPath); return fi.exists() ? fi.canonicalFilePath() : QString();#endif}/*! \obsolete Use arguments().size() instead.*/int QCoreApplication::argc(){ if (!self) { qWarning("QCoreApplication::argc: Please instantiate the QApplication object first"); return 0; } return self->d_func()->argc;}/*! \obsolete
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -