Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Deal QCommandLineParser application wide
Qt 6.11 is out! See what's new in the release blog

Deal QCommandLineParser application wide

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.1k Views
  • 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
    moravas
    wrote on last edited by
    #1

    Hi Folks,

    I cheked and tried out the QCommandLineParser class, and the correct workflow is:

    • define parser
    • set options (optional)
    • add command line options
    • parse
    • use result

    The question is what is the experience, the best practise how can I deal the result application wide?
    I'm interesting such a sulution as the QApplication class: it uses static methods that are reachable anywhere from the application, because putting the reference of the parser application wide seems to be unnecessarily complicated.
    So can anybody share the experience regarding this architectural problem?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      why is a static/global (application wide) variable more complicated than a static method?!
      I mean both need to be defined in a header file which you must include to use it.
      But if you want to use a static method create it and use a singleton pattern to return the parser object.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        You can implement a class with static getter for the parameter you need. Implement an additional static init() method which uses QCommandLineParser to initialize all the parameters (which you later can access through the static getter). Call init() in main().

        class Parameters
        {
           public:
               static void init();
               static bool flagAset();
               static QString paramB();
        
            private:
                static bool flagAValue;
                static QString paramBValue;
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

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