Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

--icon option doesn't work with QApplication in Qt > 5.5

Tags:

c++

linux

qt

I want to display the command line argument, that user provided for the application, f.e.:

./ToolOne --name

When I'm trying to get the argument from QApplication object within Qt 5.3.2 everything works. However, after using Qt 5.6.1 or 5.11.3, everything works, except the option

--icon

Any other word is working, no matter if -i or --ico. Except for --icon... Somehow, when this argument is consumed by the QApplication() it disappears.

My main function:

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QStringList arguments = a.arguments(); 
    // If argv has --icon, under Qt >= 5.6, arguments list will NOT contain icon

    MainWindow w( arguments.join(" ") );
    w.show();

    return a.exec();
}

--icon argument simply disappears in the QApplication constructor. What is worth to mention is that when I'm using QCoreApplication it works perfectly under all systems.

I tried to find any special handling in Qt or any bug report but with no result. If that matters I've checked it on:

  • CentOS 6 with Qt 5.3.2 and gcc: 4.8.2 (works)
  • RedHat 6 with Qt 5.3.2 and gcc: 4.7.2 (works)
  • RedHat 6 with Qt 5.6.1 and gcc 4.7.1 (fails)
  • RedHat 6 with Qt 5.6.1 and gcc 4.9.1 (fails)
  • CentOS 7 with Qt 5.9.2 and gcc 4.8.5 (fails)
  • RedHat 7 with Qt 5.3.2 and gcc 4.8.5 (works)
  • Fedora 29 with Qt 5.11.3 and gcc 8.2.1 (fails)

Link with small example: https://drive.google.com/drive/folders/1TGJIbzTkotnHbymTC3xDa-0PFAfG1w4n?usp=sharing

like image 332
JoshThunar Avatar asked Feb 06 '19 12:02

JoshThunar


1 Answers

It looks like -icon is synonym for -qwindowicon, by this code from Qt 5.5:

    } else if (arg == "-qwindowicon" || (isXcb && arg == "-icon")) {
        if (++i < argc) {
            icon = QString::fromLocal8Bit(argv[i]);
        }
    }

That's why it gets removed, when using Xcb. I have a hunch (no time to verify), that it is some more-or-less standard command line arg for apps using Xcb, which is why it is parsed by Qt when using Xcb.

This whole icon command line option seems to have been added in 5.4, digging in the version history. Qt 5.3 version of that source file does not handle it.

like image 194
hyde Avatar answered Nov 14 '22 09:11

hyde