Publications:Eclipse-QT
From graph-ix.net
| | This article is available under the CC By-NC-SA license. See my license details page for further information. |
This tutorial treats the process of setting up the Eclipse IDE to permit building applications using Trolltech's QT library version 4.1 under Linux. You should already be proficient in Eclipse, as basic commands are not explained in detail.
Contents |
[edit] Walkthrough
[edit] Prerequisites
- A compiled and installed copy of QT version 4.1 in its Open Source or commercial version. QT can be installed into a local userspace directory though the -prefix configure flag, e.g. ./configure -prefix /home/username/Qt-4.1.0.
- A working installation of the Eclipse SDK.
- The C/C++ Development Tools (CDT) for Eclipse need to be installed as well.
[edit] Creating a project and setting build parameters
- In Eclipse, create a new Standard Make C++ Project (not a Managed project).
- Open the project properties and add a new Builder in the Builders category and call it qmake. This new builder will be qmake which creates GCC or G++ Makefiles out of QT project files. In this case, it acts as a replacement for the CDT Makefile manager.
- As for Location, use the Browse File System button and point to the qmake binary in your QT installation, e.g. /home/username/Qt-4.1.0/bin/qmake. For the Working Directory, click the Browse Workspace button and select your topmost project directory. The path should then look similar to ${workspace_loc:/Projectname}.
- Under the Build options tab, you might want to additionally enable the During auto builds checkbox to have qmake recreate the makefile every time your project is automatically compiled.
- Close the window with OK to save the changes and move the qmake builder to the first position in the list. This ensures that qmake can create the Makefile before the compiler is run.
[edit] Adding the source code
Now would be a good time to copy source code from an existing project into your newly created one. Of course you could also create a "Hello world" application as explained by Trolltech or start writing an application from scratch.
[edit] Creating a qmake project file
- Open a shell and go to your project directory. There, run qmake -project to create an initial project file in your project directory. Do not forget to run the correct qmake binary (e.g. using the absolute path such as /home/username/Qt-4.1.0/bin/qmake) in case you already have an older version of QT installed. The syntax of qmake project files is explained in detail on Trolltech's website.
- The project file should now contain references to all source and header files in your project. Unfortunately this information needs to be updated by hand, should further files be added or removed later on. This is the only downturn of not being able to use the Managed Makefile option of the CDT.
[edit] Building and running the application
- In Eclipse, run Build Project in the Project menu. If everything went correctly, you should see the path to QT 4.1 automatically be included in the build console using the -I flag, as well as a host of additional libraries be linked such as png or X11 through the -l flag. These libraries were automatically added to the Makefile by qmake.
- If the build process finished successfully, you should be able to run your new application from a shell.
[edit] Troubleshooting
- Should you recieve complaints about the QT libraries such as libQtGui.so.4 not being found when running your application, you most likely used a different version of qmake than 4.1 to create the makefile for your project. The QTDIR environment variable is said to have no effect in QT 4.x.
