London

ANDREA

MARANGONI

  • HOME

  • ABOUT

  • PROJECTS

  • CONTACTS

    • gmail
    • github.com
    • linkedin
    • skype
    • stackoverflow
    • delicious
    • flickr
    • twitter

Developing Qt on Eclipse without plugins

22 January 2014

I am still asking myself why do they discontinued the excellent Qt plugin for Eclipse..Why?! To develop such a thing like QtCreator that is really annoying,awful and impossible to work with? (IMHO)
Well, for those like me that want still use Eclipse for developing Qt applications I will show you how to configure your environment.. linux environment indeed.

Once you created your project in your workspace, open a shell. For this tutorial we will use as project name MyQtProject.
We have to move to project directory, so:

# cd workspace/MyQtProject

We have to create our project file with extension .pro:

# qmake -project

(I will not make a digression telling you how to edit your .pro file. You know that every source file you create you should mention on it, etc, etc..)

Then we should create a main source code to start with. This will help us to achive two things:

1. Eclipse will automatically generate a makefile and will guarantee the access to all configurations of the project;
2. Eclipse will create the Debug and Release directories, so our project will be arranged as an usual Eclipse project.

So we have only to create a main.cpp file.

  int main(){
        return 0;
    }

Then we have to build it. (My shortcut is Alt+b).
Eclipse will create a Debug folder with a makefile and other files. (Please notice the lower case of makefile)

Now; right click on the project → Properties → C/C++ Build → Settings.

Tool Settings tab

Here you should configure at least Libraries specifying the path to qt libraries. In my environment located at /usr/lib/qt4/.

Another thing to configure could be the include path to have an help (shortcut Ctrl+SPACEBAR) when coding.
Under GCC C++ Compiler → Includes you will specify:

 /usr/include/qt4/Qt
 /usr/include/qt4/QtCore
 /usr/include/qt4/QtGui

Build Steps tab

Under pre-build step → Command you will write:

./qmake -makefile ../MyQtProject.pro

C/C++ Build

Now on the left tree click over C/C++ Build. Here you have to un-check the box Use default build command.
Then you have to specify another Build command. Instead of make write : make -f Makefile

Generate Makefiles automatically

Finally you have to un-check the property Generate Makefiles automatically.

That's it!

To remember

Now you are able to compile your project simply with your shortcut or on your preferred way, but you have to remember a thing.
When you want to get access to the configuration section located at Project → Properties → C/C++ Build → Settings you have to check Generate Makefiles automatically and click Apply. And then to compile your project you have to un-check the same configuration and click Apply again.


© Andrea Marangoni 2013 - All Rights Reserved.