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:
Link with small example: https://drive.google.com/drive/folders/1TGJIbzTkotnHbymTC3xDa-0PFAfG1w4n?usp=sharing
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With