Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Tweaking code refactoring options in Qt Creator



  • When writing C++ code, it's very cool to add a member function in a class header file and have Qt Creator automagically add the stub in the .cpp file for you (right-click on the function name, choose "Refactor" and then choose the option from the context menu).

    Is it possible to tweak some of that functionality, for example to add a comment such as "// TO DO..." to the function body, or stubs for functions that return values? I have looked for any configuration files that might have the templates, but so far haven't had any luck. Or is this compiled in with the sources?


  • Lifetime Qt Champion

    Hi
    I was also interested tweaking it but it seems
    its not accessible from outside. ( in any config files I could find)

    So most likely its compiled into creator via some qrc file.
    I might have missed it, so you could go looking in the source. :)



  • Hi,

    Welcome to Forum

    are you looking like this similar

    /**

    • @brief ClassName::func
      */

    type /** and then click enter.
    u will get like the above one.

    void ClassName::void func()
    {
    // func body
    }



  • For the function u can type expicitly using

    void ClassName::void func()
    {
    /*
    *
    *
    * func() Body commenting part for the repective function.
    *
    */

                  // func body
    

    }

    as above , you can type.

    Thanks,



  • @Pradeep-Kumar ... thanks for the suggestions. But it's not just about (Doxygen) comments, I know about those, too. I am also thinking about this situation:

    // in file.hpp:
    class foo {
      bool init();
    // etc. 
    };
    

    Then I get this in the .cpp file as default implementation when I refactor it:

    bool foo::init()
    {
    
    }
    

    What would be nice is to have a template which would generate this instead:

    bool foo::init() 
    {
        bool retval = true;
        // TO DO...
        return retval;
    }
    

    (of course, only if there was some trivial return type such as bool, int, or double).
    At least that way I don't forget to return something... it would even compile without warnings to that effect. OTOH it might be useful NOT to provide a default implementation so that if I forgot to implement something, the compiler would tell me... YMMV



  • @Robert-Hairgrove

    Honestly i have never tried that.
    As mentioned by @mrjj should look into the source.


Log in to reply