I am a newbie to Qt, and I was wondering if it was possible to automatically add certain functions declaration in .h file and definition in .cpp file, whenever we add new c++ source file. For ex, if I add new cpp source file(cpp + h file), Qt should add automatically add function initialiseApp(), its declaration in h file and its definition in cpp file. This should also work if I create new project. This makes my work easy as I have to add certain functions in all cpp files. Thanks :)
EDIT: Sorry for the confusion I created. I meant Qt Creator(The Editor) I just want the editor to add custom functions whenever I add new C++ source file. For Ex, whenever i add new c++ source file it should add a function called initialiseObjects() in header file(its declaration) and in cpp file(just its definition). I know that refractor option exists but i am just too lazy to type the declaration in every new cpp header file and right click on to it to add definition. Once again Sorry for the confusion created
Qt is a C++ framework. I'd assume you're talking about Qt Creator. In Creator this feature already is there. You can declare a function in
.h
and then right click on it and do Refactor => Add Definition in MyClass.cpp.Unless you just want templates to your editor (like GeneCode answered) - and then your question is unrelated to Qt as a library and depends much more on your source code editor - it is not easily possible. Some editors (notably GNU
emacs
) are easily customizable with a powerful scripting language (Elisp foremacs
). Other editors (vim
,gedit
) are extensible, notably thru plugins. YMMV.You could configure your build automation tool to do additional stuff (it is easy to add a few commands and rules in your
Makefile
). You could write some scripts or programs to generate initial source code content. You might write your own code preprocessor (or use some additional one, like GPP) or write and use some program or script generating C++ code. You could customize your compiler (e.g. developing your own GCC MELT extensions).But there is no general way, and your question is too broad, and there are cases where you don't want any automation.
Notice however that in some cases you want some of your C++ code to be generated by something else. That idea is quite common. Qt has moc.
Just go to your folder:
In here you can find all default templates and modify them there.