QCoreApplication::arguments() remove `-style` arguments passed to the app
-
Hello everyone,
I am trying to restart a GUI app with the same style set by the command line.
To start the app from the command line i do./nftminter --style Esterv.Controls.Flat
To restart the app with the same style I use
QCoreApplication::arguments()
to doQProcess::startDetached(QCoreApplication::applicationFilePath(), QCoreApplication::arguments(),QString(),&pid);
But it seems that the style is not present in the
QCoreApplication::arguments()
result.You can test that the style is not present on the output of
QCoreApplication::arguments()
with this simple example.#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { qDebug()<<"argc:"<<argc; for(int i=0;i<argc;i++) { qDebug()<<argv[i]; } QGuiApplication app(argc, argv); auto args=QCoreApplication::arguments(); qDebug()<<"argsc:"<<args.size(); qDebug()<<"args:"<<args; return app.exec(); } by executing `./nftminter --style Esterv.Controls.Flat -hello`
give the output
argc: 4 ./nftminter --style Esterv.Controls.Flat -hello argsc: 2 args: QList("./nftminter", "-hello")
It makes sense that the style is only stored on the
QGuiapplication
class and not inQCoreApplication
. But then how can i restart the app with the same style? -
@Mesrine
I cannot find the exact doc spot[*], but Qt programs recognise a certain number of command line options as "internal" to it. See https://doc.qt.io/qt-6/qcommandlineparser.html#detailsKnown limitation: the parsing of Qt options inside QCoreApplication and subclasses happens before QCommandLineParser exists, so it can't take it into account. This means any option value that looks like a builtin Qt option will be treated by QCoreApplication as a builtin Qt option. Example: --profile -reverse will lead to QGuiApplication seeing the -reverse option set, and removing it from QCoreApplication::arguments() before QCommandLineParser defines the profile option and parses the command line.
--style
is doubtless one of these.You probably need to revert to what arrived in
argv[]
if you want to replicate the exact command-line options passed to a Qt program.[*]
Found them for QGuiApplication::QGuiApplication(int &argc, char **argv).
I don't see--style
listed there. I don't know how it behaves forQCoreApplication
. But--style
seems like a reasonable additional one to specify style.
Hmm, see QApplication::QApplication(int &argc, char **argv) lists--style
as applying toQApplication
.