This tutorial consists of simple instructions to get QT C++ and eclipse development environment running on Ubuntu. I wanted to use QT 4.4 (the latest) and in order to do so we must first uncomment the backport and proposed packages in sources.list. Follow the steps below in order to accomplish this.
[Update Nov.5] This works in Intrepid Ibex however you can skip steps 2,3,4,6,7 (you must do step 5). If this confuses you, then just perform all the steps. It doesn’t make a difference in the outcome, but it just saves you time.
- Open a terminal (In the accessories category on ubuntu start menu)
- Enter the command
sudo gedit /etc/apt/sources.list
And then proceed to uncomment the two highlighted lines as shown in the picture
- Now save the gedit file and close the editor. Next we need to update our apt-cache list by entering the command
sudo apt-get update - This will go through the repositories reading all the packages and indexing them. It may take a few minutes so be patient
- Once completed we now can install the necessary qt4 packages. To do so, enter the command
sudo apt-get install qt4-designer qt4-demos qt4-doc qt4-dev-tools libqt4-devIt will prompt you that the installation takes approximately +100MB. Choose yes. - Once done we want to again, open up the sources.list and comment those lines out again. So enter the command
sudo gedit /etc/apt/sources.listand comment the lines as shown below.
Then save and close gedit.
- Now enter the command
sudo apt-get updateto return the original repositories and packages - With the terminal still open we will now enter
sudo apt-get install g++ eclipse eclipse-cdtThis will prompt you to take about ~113 MB. Choose Yes and then let it download and install. While installing perform the next step. - Go to http://trolltech.com/developer/downloads/qt/eclipse-integration-download and download the “QT Eclipse Integration for C++” file that is Linux (x86 32 bit) | gcc 4 | All editions | Qt 4.4.1
- Once done downloading the QT Plugin, and the g++/eclipse-cdt installations are finished we can extract the tar we got from the QT website. My default downloads go to /home/marf, so I will browse to /usr/local/lib and then extract the tar
cd /usr/libAnd now I enter the commandsudo tar xvf /home/marf/qt-eclipse-integration-linux.x86-1.4.1.tar.gzWhen done extracting open up eclipse with the commandeclipse -clean - There may be some messages in the terminal when opening eclipse, don’t worry that’s normal. There will probably be an initial welcome screen. You can choose just to go to the bench/workspace. You may be prompted for a default workspace location. Change it or leave it, the choice is yours. Now go to File > New > Project… and then a wizard pops up. Scroll down and choose Qt folder then QT Gui Project. Click next.
- Then input any “Project Name”, I choose test. Click Next. Then in the next window leave defaults and click Next. Finally the Last window leave defaults and click Finish. You will then get an Error window popup which says no default QT version is set. So click the “Open preferences button”.
- Now click add and then enter the settings as per the picture below.
Then click Finish and then Ok. You will be prompted that the QT version has changed and a rebuild of the project is necessary. Click Yes. It may also prompt you that this kind of project is associated with the C/C++ view, you can also accept this as it just changes the workspace layout within eclipse.
- There the project should rebuild in the background but you are done!
Now you can create QT gui or console projects, and you can even edit the qt4.ui files within eclipse using the qt4-designer (part of the qt eclipse-cdt plugin). And to compile/run a project you just go to the Project > Run.

THX nice tutorial!

Working fine.
I just created my first QT GUI in C++
when i am using “sudo apt-get install qt4-designer qt4-demos qt4-dev-tools libqt4-dev”, there is some error. it indicates that the repository don’t have qt4-demos.
And i used “apt-cache search qt4-demos” , it show nothing.
why can’t i install the qt4-demos?
thanks advance!
It’s actually not necessary to install qt4-demos. It is a demo, which just shows off different things that QT can do. But feel free to leave it out. If I use http://packages.ubuntu.com/ and search qt4-demos, It returns nothing. But if I change the distribution to hardy-backports, then it finds the package no problem ( http://packages.ubuntu.com/hardy-backports/qt4-demos ). So this makes me think that you haven’t uncommented the backports in your /etc/apt/sources.list and then performed an sudo apt-get update to update your lists. After that a sudo apt-cache search qt4-demos should turn up a positive result.
thanks for you help….
And with you help, Qt4 is running on my ubuntu now.
But there is a question, in qt assistent, there is nothing about contents , index, and I can’t use the search function.
I try to search “QString”, but It got nothing.
what’s wrong with my Qt assistent?
thanks!
Your right. I just checked mine. And Qt Assistant is the same. I don’t have time to play around with it at the moment, but by the looks of it Qt Assistant is just a front end to their API. So I suggest using this page http://doc.trolltech.com/4.4/index.html which will have all the resources you need, and specifically http://doc.trolltech.com/4.4/classes.html for searching classes. Hope that helps for now.
I solved it by install qt4-doc. but today I got a new question ,when I start eclipse, I got the error. these error display in a dialog, like below:
JVM terminated. Exit code=1
/usr/lib/jvm/java-6-sun/bin/java
-Djava.library.path=/usr/lib/jni
-Dgnu.gcj.precompiled.db.path=/var/lib/gcj-4.2/classmap.db
-Dgnu.gcj.runtime.VMClassLoader.library_control=never
-Dosgi.locking=none
-jar /usr/lib/eclipse/startup.jar
-os linux
-ws gtk
-arch x86
-launcher /usr/lib/eclipse/eclipse
-name Eclipse
-showsplash 600
-exitdata 230015
-install /usr/lib/eclipse
-vm /usr/lib/jvm/java-6-sun/bin/java
-vmargs
-Djava.library.path=/usr/lib/jni
-Dgnu.gcj.precompiled.db.path=/var/lib/gcj-4.2/classmap.db
-Dgnu.gcj.runtime.VMClassLoader.library_control=never
-Dosgi.locking=none
-jar /usr/lib/eclipse/startup.jar
And ,what is the reason? A few minites later , I change a theme, then I can run eclipse without above error now, but the theme I can’t run eclipse was download by myself from internet.
how strange things it is!
Very odd. Are you applying an Emerald theme to Gnome? Anyways thanks for letting me know it was qt4-doc, I added it to the tutorial.
I install compiz function 3D desktop on ubuntu.
do you know how to run the OpenGL/pbBuffer example of qtdemo?
on my PC ,the graphic card is ATI X550, but I can’t run the OpenGL qtdemo application.
Sorry. I don’t have a clue. I’m running an nVidia card here, so there was no problem. I think the X550 is kind of old. However I know ATI is trying to improve their linux driver support so it may improve in the near future (not sure if their linux drivers will be backwards compatable).
Hi
Thanks for the guide but I’m having some trouble. I’m on Kubuntu 8.04 with Qt 4.4, Eclipse 3.2.2 and Eclipse-cdt 3.1.2. I downloaded http://dist.trolltech.com/developer/download/qt-eclipse-integration-linux.x86_64-1.4.3.tar.gz and followed your instructions but I get no QT folder in the wizard started from File->New->Project.. !
I also tried version 1.4.1 as in your example and 1.4.0 but with the same result.
Only thing I get in Eclipse is a “Qt Designer” folder under File->New->Other..
What version of Java do you run Eclipse from ??
Did you expand the tar.gz file to /usr/local/lib or /usr/lib ??? The install description on http://trolltech.com/developer/eclipse-integration/installation-instructions-for-linux-systems seems to indicate that Ubuntu users should use /usr/lib (since this is were Synaptic / apt installs Exclipse) ??
Do you have any ideas on what I could try?
Cheers!
Fredrik
I’m downloading kubuntu 8.04 now and I will attempt to install it in Virtual Machine, and get you the results as soon as I can.
I just tried it on kubuntu and it worked like a charm. However I had to go to File->New->Other and then I saw two folders at the bottom, Qt AND Qt-Designer. Note that I expanded the tar.gz file into /usr/lib. I didn’t try in /usr/local/lib, so maybe if you change the directory, and then run eclipse -clean it will work. All the other files you used are the same versions I used with kubuntu.
Wierd that in gnome desktop the /usr/local/lib would work, but in kubuntu it seemed to need /usr/lib… so to help anybody else in the future, I changed the tutorial to show /usr/lib to avoid any confusion. Good Luck!
Hi again. Thanks for your efforts! As I said, I only get the “Qt Designer” folder under File->New->Other, however I did not think that was OK. Good to know it is.
If I go to Help->Software Updates->Manage configuration and select “Show disabled features” (third button) I can see “Qt eclipse integration 1.4.1″ as one of the disabled ones. Show properties->Status for that one gives the text:
The feature is not configured properly.
Reason:
No plug-in: “com.trolltech.qtcpp.linux.x86_64″ included at runtime.
No plug-in: “com.trolltech.qtcppproject.linux.x86_64″ included at runtime.
Could this be a java issue? What version of java do you have installed, which one is set by update-java-alternatives and which one does eclipse use as stated if you start it from a shell prompt??
I’m on two 64bit versions of Kubuntu (same result on 7.10 and 8.04) but you are using 32bit right? I’m gonna download a VMware image of the 32bit version and see if that makes a difference.
When I get home from work I can let you know what versions of java I used, however I doubt that is the problem. I did use 32 bit so I’m not sure if that is the culprit, you can double check with a 32 bit kubuntu vmware or virtualbox (I prefer virtual box).
Ok, this might be a 64bit problem since I got it to run doing the exact same thing in a 32bit Ubuntu 7.10 and a 32bit Kubuntu 8.04 with-out hassle. Only thing is I got only a Qt folder with 2 sub items when selecting new project but both Qt and Qt-designer under “Other”. Further Qt under “Other” has 4 sub items (incl the 2 found under Project/Qt).
I would be happy if you could give me details on your Java install even though.
Sorry for spamming to blog.
Well java automagically (yah.. magic) installed when I installed eclipse and eclipse-cdt. What java package version do you want? Theres java-common, java-gcj-compat…. and it goes on.
When I have some free time tomorrow or this weekend I can try installing 64 bit Kubuntu on my virtual machine and see how it goes.
Let me know if you have had any success in the meantime.
I have ubuntu 7.0.5, first i didn’t find any similar lines in sources.list to comment out so i just skipped it and followed all other steps.
now when i am opening for the qt gui project, then I needed to give path for the qt version, but i don’t find the paths. It doesn’t work ahead.
I am searching for qmake as well but i get no file or directory when i make the search like
#fine / name ‘qmake’
I needed it urgently, I will be grateful if I get the reply soon.
Solved!
All the machines I up until last post had in common but the machine giving me the problem did not have was java-gcj (I had five other jre:s installed). This is what I did to resolve my issues:
*) Install java-gcj-compat
*) run sudo update-java-alternatives -s java-gcj
*) edit /etc/eclipse/java_home to have the first line point to java-gcj
*) eclipse -clean
And all this after reading that Eclipse wasn’t to happy about java-gcj (that’s why I avoided it in the first place)! Makes me think I miss-read.
Anyway… thanks for the guide!
@Fredrik: great news. Happy QT Developing!
@RjK: try sudo find / -name qmake* and that should give a directory. If not then qmake might not have been installed by the repos.
*sigh* Now eclipse keeps setting all make file libs and such to qt3. I de-installed qt3 dev packages but still… giving up pretty soon…
Thanks Marf, I got to the qmake using it, and ran into another problem is that my qmake corresponds to qt3 and the designer I am having is of qt4. Now I am figuring out it, actually I am totally new to linux and qt, sorry if my questions are too basic..
Leave Comment