⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qcoreapplication.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
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)    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::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);            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("QCoreApplication::argc: Please instantiate the QApplication object first");        return 0;    }    return self->d_func()->argc;}/*!    \obsolete    Use arguments() instead.*/char **QCoreApplication::argv(){    if (!self) {        qWarning("QCoreApplication::argv: 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("QCoreApplication::arguments: 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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -