Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QStringList QCoreApplication::arguments (  )  [static, inherited]

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.

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. On Windows, the arguments() are not built from the contents of argv/argc, as the content does not support Unicode. Instead, the arguments() are constructed from the return value of {http://msdn2.microsoft.com/en-us/library/ms683156(VS.85).aspx}{GetCommandLine()}.

Definition at line 1795 of file qcoreapplication.cpp.

References QList< T >::at(), QList< T >::count(), QString::fromLocal8Bit(), QString::fromUtf16(), QString::prepend(), QByteArray::startsWith(), and QString::toLatin1().

Referenced by TextEdit::TextEdit().

    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()));

#if defined(Q_OS_WINCE)
    wchar_t tempFilename[512];
    if (GetModuleFileNameW(0, tempFilename, 512))
        cmdline.prepend(QString(QLatin1String("\"")) + QString::fromUtf16((unsigned short *)tempFilename) + QString(QLatin1String("\" ")));
#endif // Q_OS_WINCE

    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" ||
                l1arg == "-direct3d")
            else if (l1arg.startsWith("-style="))
            else if (l1arg == "-style" ||
                l1arg == "-session")
                stripped += arg;
        list = stripped;
    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]);

    return list;

Generated by  Doxygen 1.6.0   Back to index