Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QCoreApplication::arguments() remove `-style` arguments passed to the app
Forum Updated to NodeBB v4.3 + New Features

QCoreApplication::arguments() remove `-style` arguments passed to the app

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 215 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mesrine
    wrote on 27 Mar 2024, 11:24 last edited by Mesrine
    #1

    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 do

    QProcess::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 in QCoreApplication. But then how can i restart the app with the same style?

    J 1 Reply Last reply 27 Mar 2024, 11:39
    0
    • M Mesrine
      27 Mar 2024, 11:24

      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 do

      QProcess::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 in QCoreApplication. But then how can i restart the app with the same style?

      J Offline
      J Offline
      JonB
      wrote on 27 Mar 2024, 11:39 last edited by JonB
      #2

      @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#details

      Known 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 for QCoreApplication. But --style seems like a reasonable additional one to specify style.
      Hmm, see QApplication::QApplication(int &argc, char **argv) lists --style as applying to QApplication.

      1 Reply Last reply
      2

      1/2

      27 Mar 2024, 11:24

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved