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

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.



  • @fl0mll said in 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.

    Hi, I am trying to do the same thing but cant find the information on how to set the license file within a wizard.Can you post how you did it?
    Thanks!


  • Lifetime Qt Champion

    Hi @USchmidt,

    please see the documentation on how to add custom wizards.

    Regards



  • Hi @aha_1980,
    thanks, but I know the basics and have some custom wizards in use already, I just dont know how to set the license template file with the wizard.
    As it says here documentation :

    In the License template field, you can use predefined wizard variables to specify the path and filename of the license to use in the source and header files.
    

    But I cant find the information on which predefined variable to set. What I would like to do is to pick a license text file with the wizard (that part I know how to do) and assign it as the license info for the files created by the wizard.


  • Lifetime Qt Champion

    @USchmidt I'd just add some special template headers already containing the license.

    The predefined variables only refer to one license for now, not for different licenses per project.

    Btw, the related task is QTCREATORBUG-5783

    Regards



  • @aha_1980, ok, I was hoping to keep the license text separate, but I guess this will have to do for now.
    Thanks for your help.


Log in to reply