📄 qcoreapplication.cpp
字号:
*/void QCoreApplication::installTranslator(QTranslator * messageFile){ if (!messageFile) return; if (!QCoreApplicationPrivate::checkInstance("installTranslator")) return; QCoreApplicationPrivate *d = self->d_func(); d->translators.prepend(messageFile);#ifndef QT_NO_TRANSLATION_BUILDER if (messageFile->isEmpty()) return;#endif QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev);}/*! Removes the message file \a messageFile from the list of message files used by this application. (It does not delete the message file from the file system.) \sa installTranslator() translate(), QObject::tr()*/void QCoreApplication::removeTranslator(QTranslator * messageFile){ if (!messageFile) return; if (!QCoreApplicationPrivate::checkInstance("removeTranslator")) return; QCoreApplicationPrivate *d = self->d_func(); if (d->translators.removeAll(messageFile) && !self->closingDown()) { QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev); }}/*! \reentrant Returns the translation text for \a sourceText, by querying the installed messages files. The message files are searched from the most recently installed message file back to the first installed message 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, if the output text will be very long (as for help texts). \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. If none of the message 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 \c DefaultCodec. 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){ if (!sourceText) return QString(); if (self && !self->d_func()->translators.isEmpty()) { QList<QTranslator*>::ConstIterator it; QTranslator *messageFile; QString result; for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) { messageFile = *it; result = messageFile->translate(context, sourceText, comment); if (!result.isEmpty()) return result; } }#ifdef QT_NO_TEXTCODEC Q_UNUSED(encoding)#else if (encoding == UnicodeUTF8) return QString::fromUtf8(sourceText); else if (QTextCodec::codecForTr() != 0) return QTextCodec::codecForTr()->toUnicode(sourceText); else#endif return QString::fromLatin1(sourceText);}#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("QApplication::applicationDirPath() failed: 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("QApplication::applicationFilePath() failed: please instantiate the QApplication object first"); return QString(); }#if defined( Q_WS_WIN ) QFileInfo filePath; QT_WA({ unsigned short module_name[256]; GetModuleFileNameW(0, reinterpret_cast<wchar_t *>(module_name), sizeof(module_name)); filePath = QString::fromUtf16(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) QFileInfo fi(qAppFileName()); return fi.exists() ? fi.canonicalFilePath() : QString();#else# 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("/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); if (QFile::exists(candidate)) { 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("QApplication::argc() failed: please instantiate the QApplication object first"); return 0; } return self->d_func()->argc;}/*! \obsolete Use arguments() instead.*/char **QCoreApplication::argv(){ if (!self) { qWarning("QApplication::argv() failed: please instantiate the QApplication object first"); return 0; } return self->d_func()->argv;}/*! \since 4.1 Returns the list of command-line arguments. arguments().at(0) is the program name, arguments().at(1) is the first argument, and arguments().last() is the last argument. Calling this function is slow - you should store the result in a variable when parsing the command line. \warning On Unix, this list is built from the argc and argv parameters passed to the constructor in the main() function. The string-data in argv is interpreted using QString::fromLocal8Bit(); hence it is not possible to pass i.e. Japanese command line arguments on a system that runs in a latin1 locale. Most modern Unix systems do not have this limitation, as they are Unicode based. On NT-based Windows, this limitation does not apply either.*/QStringList QCoreApplication::arguments(){ QStringList list; if (!self) { qWarning("QApplication::arguments() failed: please instantiate the QApplication object first"); return list; }#ifdef Q_OS_WIN QString cmdline = QT_WA_INLINE(QString::fromUtf16((unsigned short *)GetCommandLineW()), QString::fromLocal8Bit(GetCommandLineA())); extern QStringList qWinCmdArgs(QString cmdLine); list = qWinCmdArgs(cmdline); if (self->d_func()->application_type) { // GUI app? Skip known - see qapplication.cpp QStringList stripped; for (int a = 0; a < list.count(); ++a) { QString arg = list.at(a); QByteArray l1arg = arg.toLatin1(); if (l1arg == "-qdevel" || l1arg == "-qdebug" || l1arg == "-reverse" || l1arg == "-widgetcount") ; else if (l1arg.startsWith("-style=")) ; else if (l1arg == "-style" || l1arg == "-session") ++a; else stripped += arg; } list = stripped; }#else const int ac = self->d_func()->argc; char ** const av = self->d_func()->argv; for (int a = 0; a < ac; ++a) { list << QString::fromLocal8Bit(av[a]); }#endif return list;}/*! \property QCoreApplication::organizationName \brief the name of the organization that wrote this application The value is used by the QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a QSettings object is created. On Mac, QSettings uses organizationDomain() as the organization if it's not an empty string; otherwise it uses organizationName(). On all other platforms, QSettings uses organizationName() as the organization. \sa organizationDomain applicationName*/void QCoreApplication::setOrganizationName(const QString &orgName){ coreappdata()->orgName = orgName;}QString QCoreApplication::organizationName(){ return coreappdata()->orgName;}/*! \property QCoreApplication::organizationDomain \brief the Internet domain of the organization that wrote this application The value is used by the QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a QSettings object is created. On Mac, QSettings uses organizationDomain() as the organization if it's not an empty string; otherwise it uses organizationName(). On all other platforms, QSettings uses organizationName() as the organization. \sa organizationName applicationName*/void QCoreApplication::setOrganizationDomain(const QString &orgDomain){ coreappdata()->orgDomain = orgDomain;}QString QCoreApplication::organizationDomain(){ return coreappdata()->orgDomain;}/*! \property QCoreApplication::applicationName \brief the name of this application The value is used by the QSettings class when it is constructed using the empty constructor. This saves having to repeat this information each time a QSettings object is created. \sa organizationName organizationDomain*/void QCoreApplication::setApplicationName(const QString &application){ coreappdata()->application = application;}QString QCoreApplication::applicationName(){ return coreappdata()->application;}#ifndef QT_NO_LIBRARYQ_GLOBAL_STATIC_WITH_ARGS(QMutex, libraryPathMutex, (QMutex::Recursive))/*! Returns a list of paths that the application will search when dynamically loading libraries. This list will include the installation directory for plugins if it exists (the default installation directory for plugins is \c INSTALL/plugins, where \c INSTALL is the directory where Qt was installed). The directory of the application executable (NOT the working directory) is always added, as well as the colon separated entries of the QT_PLUGIN_PATH environment variable. If you want to iterate over the list, you can use the \l foreach pseudo-keyword:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -