Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include needed headers automatically in QT Creator

I have a project in QT Creator and I want that the header files be included automatically when using a new object. It's like in Eclipse : Add needed headers when invoking a new object by using Ctrl+Alt+Space : all needed headers will be included.

Here is an example

#include <QApplication>
#include <QPushButton>  /* Header that i want to include automatically */

 int main( int argc, char *argv[ ] )
{
    QApplication app( argc, argv) ;
    QWidget fenetre;
/*Add needed headers when invoking a new object like ctrl+alt+space in eclipse*/
    QPushButton bouton( "Bonjour", &fenetre) ;
    bouton. move(70,60);
    fenetre. show( ) ;
    return app. exec( ) ;
}

Any suggestions on how to do this in QT Creator ? Thanks

like image 992
The Beast Avatar asked Jan 20 '16 20:01

The Beast


2 Answers

In QT Creator version 4.1.0 you have option for that under right click (move your cursor over type you want to include, click, choose refactor and there it is)

shortcut for that is (Alt+Return) to trigger quick fix , you can see what is the shortcut for it if it does not work on your machine Tools -> Options -> Environment -> Keyboard (Search for quickfix).

like image 73
sebekk23 Avatar answered Sep 28 '22 06:09

sebekk23


Not exactly as you requested, but: if you would like to create a new class with the help of Qt Creator you can certainly have Qt Creator taking care of immediate include files as well:

enter image description here

Qt Documentation: Creating Projects.

like image 37
Alexander V Avatar answered Sep 28 '22 05:09

Alexander V