QtCreator License Template for Projects?



  • Does anyone have a solution to set a custom license header for any project. Currently I use Tools -> Options -> C++ -> File Naming -> License Template to generate the comment header for all generated files. But sometimes I work on projects with different header templates. So I want to set a custom template file for any project.

    Any ideas?

    ADD:
    I created some custom wizards for my company so I select the license at the wizard.



  • I took a look at the QtCreator code https://github.com/qtproject/qt-creator/blob/master/src/plugins/cpptools/abstracteditorsupport.cpp. It looks like that nothing is implemented for a solution.

    QString AbstractEditorSupport::licenseTemplate(const QString &file, const QString &className)
    {
        const QString license = Internal::CppFileSettings::licenseTemplate();
        Utils::MacroExpander expander;
        expander.registerVariable("Cpp:License:FileName", tr("The file name."),
                                  [file]() { return Utils::FileName::fromString(file).fileName(); });
        expander.registerVariable("Cpp:License:ClassName", tr("The class name."),
                                  [className]() { return className; });
    
        return Utils::TemplateEngine::processText(&expander, license, 0);
    }
    

    But I think it easy could be integrated. What's the right way to get a information out of the .pro file?

    1. Extend the object Project by method licenseTemplate() -> It should return the path to the license header template file of the project.
    2. Set the licenseTemplate member variable by a variable at the .pro file like LICESENE_TEMPLATE
    LICENSE_TEMPLATE = "~/path-to-the-template-file/template-file.h"
    

    I want to access the LICENSE_TEMPLATE from the .pro file at the AbstractEditorSupport::licenseTemplate() method. Can anyone help me?


  • Lifetime Qt Champion

    Hi,

    Looks like an interesting feature for Qt Creator. That's something you should bring to the Qt Creator mailing list. You'll find there Qt Creator's developers/maintainers. This forum is more user oriented.



  • @SGaist Thank you for the information. I will post it at the mailling list and if I had time I will implement this feature and submit a pull request on github.


  • Lifetime Qt Champion

    Github is just a mirror, it's not used at all for Qt development.

    The official repositories are on https://code.qt.io

    For submission, you have to go through gerrit.



  • @SGaist Thank you! I will try it and post the solution here.


Log in to reply
 

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