Wednesday, March 04, 2009

Qt Eclipse Integration

Recently, I started to play with Qt 4 also under Windows, in order to be able to port some of my Linux applications that use Qt. Usually, I'm using KDevelop under Linux to develop Qt applications, but under Windows? Then I noticed that Trolltech provides Qt Eclipse Integration, i.e., an Eclipse plugin to program Qt programs with Eclipse. So I gave it a try...

IMPRESSIVE, really a nice piece of software!

The installation is immediate, and you get a menu item to run Eclipse already setup to start programming with Qt (relying on the CDT plugin for the C++ part). To try it, I followed the tutorial you find here.

The new project wizard now provides also Qt project options:

I chose the Qt Gui Project, and you'll have a skeleton project with an ui file (and you can then choose possible further libraries you might want to use):

If you haven't done that already, you'll need to configure a Qt version by providing the paths of your Qt installation:

Building the project relies, obviously, on qmake:

If you open the ui file, you'll see the nice integration with QtDesigner, perfectly fit in Eclipse, with all the useful views:

You can then create new files, classes and in particular UI classes:

And note the nice project file editor

And here's how you can easily manage signals and slots:

Following the tutorial you'll get an address book application that looks like this:

Summarizing, the qt eclipse integration plugin really impressed me in a positive way! And now I want to try it also under Linux. :-)


Gio said...

Amazing! I mean, Betto using Windows??? :-P
Joking aside, the QT Eclipse integration it's definitely interesting and QT is one of (the many) things I'd like to experiment with.

betto said...

ehm... I'm using also Windows to port my programs O:-)
Qt reeeeaaallly ROCKS!

dashesy said...

QT rocks and Eclipse too.
I tried QT creator first but it seems (as always) reinventing the wheels is not a good idea, I hope Nokia continues to support the QT-Eclipse integration in the future.

betto said...

I must admit that after trying to use qt eclipse integration and qt-creator I definitely preferred to use qt-creator for qt development. Although I'm a really big fan of eclipse, I found that the qt integration still lacks many features (e.g., qmake run customization), while qt-creator gets better every day... let's see what comes in the future :)

Myzhar said...

I'm searching for a solution to a problem... did you ever try to import a Custom Widget in Eclipse?

I'm trying since 3 days with non positive results.


nitin_dhiman said...

Liked your blog! I started using Qt with Eclipse Helios on Debian.
I am trying to run Address book example but I am encountering a qmake option problem.
Eclipse executes following command:
/usr/bin/qmake -recursive CONFIG+=debug_and_release

and Qmake complaints ***Unknown option -recursive

i think in lates versions of qmake,recursive is by default.

I could not locate where i can customize qmake for project specific settings.
Can you suggest me something on it?


betto said...

probably you have an older version of qmake which does not support -recursive option?

Furthermore, what do you mean 'customize qmake'?


nitin_dhiman said...

Thanks for reply.
By customize i mean how I can pass various options for qmake.

I found /usr/bin/qmake was linked to qmake-qt3. Corrected the link to qmake-qt4 and error was resolved.
Application did got compiled and display was generated.

But Editor in Eclipse was showing error " undefined reference to `AddressBook::staticMetaObject' " on Q_OBJECT in class declaration.
IMHO it is related to indexer but could not find any solution to fix this!
Did you encountered any such problem?

betto said...

If you had already tried to run another version of qmake that probably left some old files around... please make sure to clean your project... that's only a guess though...

and also make sure you use shadow builds (i.e., build in a directory different from the source directory)

nitin_dhiman said...

thanks betto,
cleaning project did helped. But one thing did surprised me about Qt-Eclipse plugin is updation of include path and library paths. It took me some time to figure out I need to manually update .pro file for these. Updating include path in project properties (using gui right-click-project -> properties-> c/c++ include path
and ..->properties->c/c++ Project paths->Libraries) is not getting reflected in project file.

Is my observation correct?

betto said...

I'm afraid I can't answer this... I haven't been using qt integration for a long time... try to ask in the qt mailing list...

all I can say is that you should find a way to tell eclipse where to find include files and libraries (probably setting some environment variables in the build configuration?), and NEVER put this stuff in the .pro file ;)