Important: Please read the Qt Code of Conduct -

[SOLVED] customizing templates for source/header files

  • Hi -

    I'm sure there's a way to do this, so I'll ask: how do I modify the templates that are provided when I create a new file through Creator? I'd like to elaborate on the template for the header files, and create one for the source files (since none seems to exist).


  • Is QtCreator/share/qtcreator/templates what your are looking for?

  • I can't find such a directory structure in my file system; where does this reside?


  • What is your system ?

    In my installation, on Windows 7, I have : C:\Qt\QtCreator\share\qtcreator\templates

    More generic : %QTDIR%\QtCreator\share\qtcreator\templates

  • Hmm...I'm on a Mac, and have no such directory. I also did an mdfind on qtcreator with no success.

    Maybe someone else can fill in the blank here.

  • According to the Qt Creator sources the directory is the same for all platforms. You'll find a listing "here": if you want to locate the directory by its contents.

  • Weird...I'm not finding any of that on my system.

  • Where is Qt installed? When I installed Qt I installed it to my home directory to keep it seperately so for me it's /home/bobby/QtSDK/QtCreator

    How do you run QtCreator? Look at it's executable path from how you're calling it.

  • Qt is installed in /Developer/Applications/Qt on my system disk. I run Qt Creator by clicking on a dock icon that points to the file "Qt Creator" in that directory.

  • I don't have access to a Mac right now but try opening the terminal utility and run:

    find / -iname 'qt4project'

    Then it should give you the path to that template

  • Hi, Bobby -

    I tried that, and got reams of output. Is there a way to filter out the extraneous information?

  • try looking for 'qtquick10'

  • @sh-3.2# find / -iname '*qtquick10'
    find: /dev/fd/3: Not a directory
    find: /dev/fd/4: Not a directory

  • I dont know much about Qt on Mac, But have you checked /usr/local/Trolltech/Qt-4.7.2/ or something similar to this ?

  • Hi, Rahul –

    I don't have a Trolltech directory under /usr/local.

  • Based on this "doc":, You would have set the PATH during installation i guess. So, looking at PATH may give u hint..

  • I have no idea what's going on now. I just installed the new release, and I still don't have a Trolltech directory anywhere that I can find.

    Here's where I installed it, and what I got:

    @Macintosh-d49a20f3c0dc:Qt mzimmers$ pwd
    Macintosh-d49a20f3c0dc:Qt mzimmers$ ls InstallationLog.txt SDKMaintenanceTool.ini
    Changelog.txt Licenses Simulator
    Demos Madde Symbian
    Desktop Qt components.xml
    Documentation readme
    Examples SDKMaintenanceTool.dat

    It wanted to install into a directory under my username, but I prefer keeping my apps in a more centralized location.

  • Qt might be an "application bundle":, "containing": all the files for Qt Creator, including the ones you are looking for.

  • You will find the templates for the stand alone Qt Creator app in


    The templates for the C++ files are in the subfolder "qt4project".

    Replace "/Applications" with the folder where you have put the Qt Creator binary.

    The path may be different for SDK downloads, I never checked those.

  • Hey, thanks, Volker:

    Here's the contents of my folder:
    @Macintosh-d49a20f3c0dc:qt4project mzimmers$ ls
    customwidgetwizard mywidget.h widget.ui
    main.cpp mywidget_form.cpp
    mywidget.cpp mywidget_form.h
    Macintosh-d49a20f3c0dc:qt4project mzimmers$

    Neither of the .h files seem to match what I get when I create a new .h file. Do the default contents for new files come from somewhere else, perhaps?

  • I just checked the sources. The contents of a new header file is hard coded into Qt Creator. It is always of the format



    The only thing you can customize is a license template, that is prepended on the very top of the file.

    The same holds for a single new C++ source file, with the exception, that this one is plain empty (it only contains a single newline, and optionally the license template).

    I'm sorry - you will either need to hack Qt Creator (in file qt-creator-master/src/plugins/cppeditor/cppfilewizard.cpp) or live with the current "template".

  • OK, I can live with that (though I do find it a bit surprising that it's not configurable).

    This is actually good news in a way...during the fact-finding while this thread was going on, I was starting to think I was crazy.

    Thanks, V.


Log in to reply