QT and Eclipse C++ Development in Ubuntu Linux
August 21st, 2008

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.

  1. Open a terminal (In the accessories category on ubuntu start menu)
  2. Enter the command sudo gedit /etc/apt/sources.list
    And then proceed to uncomment the two highlighted lines as shown in the picture
    Step 1
  3. 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
  4. This will go through the repositories reading all the packages and indexing them. It may take a few minutes so be patient
  5. 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-dev It will prompt you that the installation takes approximately +100MB. Choose yes.
  6. 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.list and comment the lines as shown below.
    Step 2

    Then save and close gedit.

  7. Now enter the command sudo apt-get update to return the original repositories and packages
  8. With the terminal still open we will now enter sudo apt-get install g++ eclipse eclipse-cdt This will prompt you to take about ~113 MB. Choose Yes and then let it download and install. While installing perform the next step.
  9. Go to http://trolltech.com/developer/eclipse-integration and download the “QT Eclipse Integration for C++” file that is Linux (x86 32 bit) | gcc 4 | All editions | Qt 4.4.1
  10. 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/lib And now I enter the command sudo tar xvf /home/marf/qt-eclipse-integration-linux.x86-1.4.1.tar.gz When done extracting open up eclipse with the command eclipse -clean
  11. 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. Step 3
  12. 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”.
    Step 4
  13. Now click add and then enter the settings as per the picture below. Step 5

    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.

  14. 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.



schilkschi
September 12th, 2008 at 3:45 pm

THX nice tutorial!
Working fine.
I just created my first QT GUI in C++
;)

tangher
September 22nd, 2008 at 10:42 am

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!

Marf
September 22nd, 2008 at 1:36 pm

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.

tangher
September 23rd, 2008 at 8:55 am

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!

Marf
September 23rd, 2008 at 7:48 pm

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.

tangher
September 24th, 2008 at 11:04 am

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!

Marf
September 24th, 2008 at 5:45 pm

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. :)

tangher
September 25th, 2008 at 6:15 am

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.

Marf
September 25th, 2008 at 7:54 pm

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).

Fredrik
September 30th, 2008 at 5:45 pm

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

Marf
September 30th, 2008 at 7:02 pm

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. :)

Marf
September 30th, 2008 at 9:17 pm

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!

Fredrik
October 1st, 2008 at 4:22 am

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.

Marf
October 1st, 2008 at 8:19 am

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).

Fredrik
October 1st, 2008 at 9:16 am

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. :)

Marf
October 1st, 2008 at 8:39 pm

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.

RjK
October 2nd, 2008 at 3:16 am

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.

Fredrik
October 2nd, 2008 at 4:57 am

There is the sun-java-5 package, sun-java-6, icedtea etc. If you run “update-java-…” (can’t remember the exact name of the command, just press tab since there is only one) with the argument –list that would be useful. Also if you could give me the contents of your /etc/eclipse/java_home file and tell me what eclipse dumps in relation to what java version it found in a terminal window if you start it from there I would appreciate it. :)

I’m out of ideas. Posted a question here: http://www.qtcentre.org/forum/f-installation-and-deployment-5/t-eclipse-integration-in-kubuntuubuntu-64-bit-16312.html

Any input appreciated!

Fredrik
October 2nd, 2008 at 6:34 am

Ok, I’m really sorry for writing so much on your blog but I need to update you with that I just downloaded and installed two fresh 8.04 amd64 versions of Ubuntu and Kubuntu in VMware. It works on both of them! My install must be really borked so I guess I need to keep digging. Annoying. :)

Fredrik
October 2nd, 2008 at 6:48 am

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!

Marf
October 2nd, 2008 at 7:26 am

@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.

Fredrik
October 2nd, 2008 at 8:09 am

*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…

RjK
October 3rd, 2008 at 3:07 am

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..

rac
December 15th, 2008 at 6:24 am

good howto ;-)
The path to download qt has changed on trolltech site it’s now http://trolltech.com/developer/eclipse-integration

btw. if you dont use eclipse from repo…. don’t try to directly extract it to the eclipse folder because the tar file includes a folder named eclipse and this will overwrite the eclipse binary file :-/

ruben
January 20th, 2009 at 7:45 am

Hi!

The installation is complete but doesn’t work well.
When I type something like :
var.

or

var->

My system blocks?? Takes like one minute to open the cdt options. Please help

rockballad
February 15th, 2009 at 10:34 pm

Hi, I get the error:

make: *** No rule to make target `debug’.

Look it’s familiar but I don’t know how to fix. /usr/bin contains qmake, why does it recognize?

Thanks.

Marf
February 16th, 2009 at 6:16 pm

is this when you are trying to compile your own project? after the installation in eclipse has worked?

Catstail
February 21st, 2009 at 6:20 pm

Hi,

I get the same error as rockballad:

make debug
make: *** No rule to make target `debug’. Stop.

The project I tried to build was “AddressBook” example.

Installation seemed to go OK and /usr/bin contains qmake (link to /etc/alternatives/qmake) and also qmake-qt3 and qmake-qt4 files.

pablopaniagua
March 9th, 2009 at 4:30 pm

I can’t run a qt project, i’m confused when i press rightclick->run
it shows a window . Somebody run a qt project?

pablopaniagua
March 9th, 2009 at 11:06 pm

The exact problem that i have, is that the build project is not working, somebody help me please.

Alejo
April 19th, 2009 at 7:06 pm

I’m using the open source version of Qt which I downloaded via the “Add/Remove applications” feature in ubuntu. Would you happen to know what I’m supposed to input as Qt version in eclipse? I tried what you put in your tutorial (QT4.4), but I keep getting the following error that several others seem to be getting:
make: *** No rule to make target `debug’. Stop.
I’m guessing that I have input the wrong version? Any help would be appreciated

Graf
May 13th, 2009 at 4:33 pm

Yes, exactly the same problem with “make: *** No rule to make target `debug’. Stop.”
Did it exactly like in the instructions. Have no idea how to fix…

Graf
May 13th, 2009 at 4:46 pm

Just found an easy way to check, if anything is alright with QT. Went to he workspace directory, then to the project directory (/home/pavel/workspaces/Test), did qmake first, then make. Both the qmake and make processes not failed, the executable was created with the name Test, I managed to run it and saw an empty window (exactly what empty project is about). So this is problem with Eclipse, not Qt. Still have no idea how to fix it, doing qmake and make by hand is not a solution, why I need Eclipse then?

Leave Comment


Nickname (required)

E-Mail (required)

Website



Highest Rated



© M.Aldworth of Infinite Designs
Any other work is copyrighted to their respective owners if not specified other wise.