1

I've been using Qt for a while and I couldn't find two options:

  1. Default project template. In other words, whenever I create a new project, it would already have:

    #include <iostream> #include <cstdlib> #include <iomanip> /* author: $author * $date */ using namespace std; int main(int argc, char *argv[]) { } 
  2. I'd like to have the compiler flags -Wall -pedantic -std=c++11 on by default. I know I could add the flags by adding lines to the project .pro file but it seems very cumbersome having to do that for every single project.

I tried googling but only could find methods that involved doing things separately for every single project.

2 Answers 2

2

There are two approaches.

Qt Creator Project Settings

For projects you've already created and don't intend to change, you can add "CONFIG+=c++11 warn_on" as a qmake argument in the project build configuration in Qt Creator:

Example Project Settings in Qt Creator

You can then propagate those settings to shared project settings that become the default for all projects whose builds you haven't configured yet.

This is most helpful if you have lots of projects that you don't wish to modify.

Templates

You can create new projects from a template that has the settings you want. The template includes the prototypical files that constitute a project, e.g. the .pro file, source/header files, README, LICENSE, a default icon, etc. - anything you wish, really.

Qt Creator templates are built up of simple text files that are preprocessed by Qt Creator to substitute entries from the wizard. The wizards can be described in two ways: an older XML-based format, and a newer JSON-based format. See the documentation for more details.

I have an example of a simple XML-based wizard that I use to quickly create StackOverflow answers:

https://github.com/KubaO/stackoverflown/tree/master/qtcreator-templates

I'd like to have the compiler flags -Wall -pedantic -std=c++11 on by default.

Instead of using platform-specific options, use the cross-platform configuration options. The template should have the following in its .pro file:

CONFIG += c++11 warn_on 

These are documented.

Sign up to request clarification or add additional context in comments.

3 Comments

Unless I misunderstand you, the .pro files are project specific so if I want those flags, I need to add them for every project?
Nevermind, you meant the .pro file in the wizard folder, correct?
Yes. An alternate option is to edit a top-level .user file. I've added it to the answer.
0

I am sorry but qtcreator don't seems to be able to manage the templates for now. What you can do is to get the sources of qtcreator, do the changes you want and then compile an install it. I don't see any other ways to do it. For example, if you want to add the using namespace in the main.cpp, go to qt-creator/share/qtcreator/templates/qt4project/main.cpp and add it.

4 Comments

Perhaps you mean that Qt Creator itself has no project type for a template, but it has certainly provided support for using the templates for a long time.
I mean that I don't see anywhere we can change the Qt Creator templates without change them in the code itself.
These templates are deployed as text files in Qt Creator's installation folder. They are trivial to modify there, and you can add your own. You don't need to touch Qt Creator's source code at all. See here for a trivial example and instructions about how to install it - no need to build anything, you only need to copy the template into a location where Qt Creator looks for them.
Ho nice ! I didn't knew that. Thank you !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.