PDA

View Full Version : Qt Creator Changing the default C++ Class template



wookie1
26th June 2012, 01:08
Hi I'm trying to find where the template is kept for the C++ class so I can edit the header and the implementation file to include some other bits and pieces, but I can't seem to locate them. I've found the other wizards as described http://doc.qt.nokia.com/qtcreator-2.4/creator-project-wizards.html but I can't find the class wizard there. Does anyone know where it might be.
Thanks.

ChrisW67
26th June 2012, 01:46
You can include a licence template to be included at the top of new h and cpp files using Tools > Options > C++ > File Naming.

On my Linux box there are buckets of templates under: /usr/share/qtcreator/templates
I am sure you can find the equivalent location on your platform.

wookie1
26th June 2012, 02:04
This is where I was expecting to find it but as far as I can tell its not there.

ChrisW67
26th June 2012, 02:23
How have you installed Qt Creator? Part of the Qt SDK... then look under {path to}/QtSDK/QtCreator/share/qtcreator/templates.

Failing that, open a shell and type:


locate -b qt4project
# OR
find / -type d -name qt4project

wookie1
26th June 2012, 13:07
Sorry I should have been clearer the file exists, and QtCreator is installed. The problem is none of the files in templates or the sub folders appear to relate to the new class template.

Timmmm
18th September 2013, 19:26
I also wanted to know this, since I much prefer having `#pragma once` to the old and hacky #include guards.

Unfortunately it is all hard-coded so you would need to recompile QtCreator to change the template:

https://qt.gitorious.org/qt-creator/qt-creator/source/5d15076ea14262b474dd60768e6d80ef498cfdd1:src/plugins/cppeditor/cppclasswizard.cpp#L199

ChrisW67
18th September 2013, 21:03
At least those "old and hacky" include guards are guaranteed to work everywhere unlike the non-standard "#pragma once". Feel free to propose the patch to make this either fully templated or optionally use the pragma.