PDA

View Full Version : Howto use Eclipse with QT4 in 10 steps



the_bis
27th January 2007, 10:30
I write this simple howto that explains how to setup and use Eclipse to build QT4 applications.
I hope this is useful for QT programmaers ;-)
the_bis



Howto use Eclipse with QT4 in 10 steps

QT version: 4.2.2-x11
Eclipse version: eclipse-*-3.1.2-1jpp_15fc
Linux distro: Fedora Core 5

1. Choose your existing QT project
For example my project was in "/home/test/myQTProj" and my files are: myQTProj.pro, main.cpp, myQTProj.h, myQTProj.cpp

2. Setup environment
Check if you have the right environment path. In my sytem I have to set the $PATH variable:
export PATH=/usr/local/Trolltech/Qt-4.2.2/bin:$PATH

3. Launch Eclipse

4. Set up eclipse for use with Qt
Set the right path to reach "qmake" and "assitant". To do so click on "Run/External Tools/External Tools" menu and create 2 new "Program":

- Name: QMake
- Location: /usr/local/Trolltech/Qt-4.2.2/bin/qmake (change it to your needs)

- Name: QTAssistant
- Location: /usr/local/Trolltech/Qt-4.2.2/bin/assistant (change it to your needs)

Create the right file-type associations to handle QT Designer and Linguist files. To do so click "Window/Preferences/General/Editors/File Associations" and add file extensions for .ui and .ts files:
- *.ui -> designer
- *.ts -> linguist

Note: this setup has to be done only the first time you use Eclipse.

5. Create a workspace for use with your C++ QT project
Create a new "Standard Make C++ Project" (with the "File/New/Standard Make C++ Project" dialog).
Choose a name for your project.
Unflag "Project contents/Use default" and choose your existing project directory.
Click "Next" button and at tab named "C/C++ Indexer" (the last one) choose "Full C/C++ Indexer".
Click "Finish".
You will see all your project sub-directories, "*.cpp", "*.h" and "*.pro" files in the left "C/C++ Projects" panel.

6. Create our make targets
Open up the "Make Targets View" in Eclipse ("Window/Show View/Make Targets" - in my setup this is on the right part of the Eclipse window), click right-mouse on the project's name and add two new "Targets":

- Target Name: qmake
- Make Target: myQTProj.pro (change it to your needs)
- Build Command: qmake (unflag and change this option)

- Target Name: all
- Make Target: all
- Build Command: default (make)

7. Make "Makefile" -> run qmake command
Double click on the "qmake" target and take a look to the "Console" View in Eclipse. If the command was successfull, there is now a makefile in your project directory which can be used to build your app program.

8. Make your executable -> run make command
Double click on the "make" target to build your QT application.

9. Note
If will start the C/C++ Indexer don't worry: it will take some minutes to browse all the files it needs. The problem is that the Indexer continue to start and slow down the coding work... Any solution?
This howto was inspired by this article: Qt4 in Eclipse - http://scroogie.de/index.php?/archives/61-Qt4-in-Eclipse.html

10. Enjoy ;-)

wysota
27th January 2007, 10:57
Maybe you could also add it to our wiki (http://wiki.qtcentre.org)?

the_bis
27th January 2007, 17:31
Maybe you could also add it to our wiki (http://wiki.qtcentre.org)?

Done ;)
You can find it here: http://wiki.qtcentre.org/index.php?title=Howto_use_Eclipse_with_QT4_in_10_s teps

the_bis

yop
28th January 2007, 20:21
A few more that I use:
For step 4 you could use QtClipse (http://artis.imag.fr/Membres/Xavier.Decoret/resources/qt/eclipse/wiki/index.php/Main_Page). The first versions waren't that much but now it's pretty usable and straightforward. You just get some syntax highlighting for .pro files and easy invocation of qmake on .pro files. Simple and effective. Also I would suggest under Project->Properties->C/C++ Include Paths to add the path to the Qt headers so you get code completion for Qt. I 'm using Eclipse 3.2.1 on Ubuntu and Windows.