Deal QCommandLineParser application wide



  • 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


  • Moderators

    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.


  • Moderators

    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;
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.