diumenge, 30 de setembre del 2007

NetBeans 5.5 with C++ and Qt

In this post I want to explain to you how I can make a C++/Qt program using the Sun IDE Netbeans.
First of all, I tried to do it with both NetBeans and Eclipse. However, I finally choose the first because Eclipse is really hard and uses many computer resources. In addition, I feel the window view of NetBeans more atracttive than Eclipse one.

So, the steps I neede to follow to reach my goal are explained on the next lines (I work with Ubuntu Feisty):
  1. NetBeans instalation (download page) :
    • $ chmod 777 netbeans-5_5_1-linux.bin
    • $ sudo ./netbeans-5_5_1-linux.bin
  2. NetBeans C/C++ Pack instalation (download page):
    • $ chmod 777 netbeans-c++-5_5_1_u1-linux.bin
    • $ sudo ./netbeans-c++-5_5_1_u1-linux.bin
  3. Configure the C++ libraries (directories where .h files can be found) because NetBeans default configuration doesn't include them. In order to manage this configuration I had to go to: Tools -> Options -> C/C++ -> Code Assistance -> C++ Compiler. Once there I had to add all the C++ directories:
    /usr/include/c++/4.1.2/backward/
    /usr/include/c++/4.1.2/bits/
    /usr/include/c++/4.1.2/debug/
    /usr/include/c++/4.1.2/ext/
    /usr/include/c++/4.1.2/i486-linux-gnu/
    /usr/include/c++/4.1.2/tr1/
    /usr/include/c++/4.1.2/
    /usr/include/ /usr/local/include/
    /usr/lib/gcc/i486-linux-gnu/4.1.2/include/
    Some of them are redundant, but I added also.
    You can see the window in the next image:

  4. Configure the Qt libraries (directories where .h files can be found). In order to get this configuration I had to do right click on the project and then: Properties -> C/C++ -> C++ Compiler -> General -> Include Directories. Once there I had to include the Qt directory (/usr/include/qt4/ in my system):
In this moment NetBeans is configured and we can use C++ amb Qt!! :D
Here is a little peace of code:

#include <stdlib.h>
#include <QtGui/QApplication>
#include <QtGui/QPushButton>

int main(int argc, char** argv)
{
QApplication qapplication(argc, argv);
QPushButton hello("hello", 0);
hello.show();
return qapplication.exec();
}

And this is the explanation ^^

12 comentaris:

GironaMola ha dit...

Ei!

M'he quedat sorpres de trobar aquest post! Em dic Jordi i estic a UK. Estic barallant-me amb l'Ubuntu per desenvolupar un analitzador d'audio (frequencia) en temps real.

Porto un temps fent servir el Netbeans amb la opcio de c++. Pero degut a que no hi ha massa documentacio em faig un liu amb el tema d'afegir Includes i Libs.

Jo he comensat a jugar una mica amb el GTK+. Que tal el QT?

Molta salut Milana!

Milana ha dit...

Ostras!
En rebre el teu comentari em pensava que era d'un amic meu de la uni que també es diu Jordi i en llegir que estava a UK he al·lucinat una mica XDD.
Encantada de conèixer-te Jordi!

En quant a NetBeans..., la veritat és que em va donar molt la tabarra per poder-ho fer quadrar tot. Fins i tot vaig pensar en utilitzar Eclipse, on és molt més fàcil això de manegar llibreries. Però a causa del gran gast de recursos que té aquest conegut IDE vaig decidir trencar-me les banyes i aconseguir que NetBeans passés per allí on volia jo, que sinó el meu portàtil semblava que anés a enlairar-se d'un moment a l'altre XDD.

En quant a Qt, hi he treballat poc, però de moment bé. És clar però que, al treballar amb Gnome (utilitzo Ubuntu) no és l'opció amb que tot queda més harmònic, però què s'hi farà :D.

GironaMola ha dit...

Merci!

Estic una mica rallat perque el netbeans em sembla de collons pero m'esta fallant per exemple en el tema de "l'AutoCompletition". He decidit abandonar el linux per un temps i aprofundir els meus coneixaments de C#. Espero que quan hagi trobat una feina pugui dedicar una mica mes de temps al C++ i al linux en general!

Jo tambe utilitzo Ubuntu, es de meravella!

Merci!

Milana ha dit...

Sí, és el problema que jo també li veig al NetBeans, que com a IDE de C++ no està massa ben aconseguit. Però bé, s'haurà de confiar, a veure si la comunitat se n'encarrega d'arrelgar-ho :D.

Molta sort amb la feina! ^^
Ubuntu power!! :D

Anònim ha dit...

hello


Can you tell me please how I can build Qt-projects under netbeans?

Don't found any options to set qmake or something else.


Thanks


blabub

Milana ha dit...

Hi blabub!

Excuse me for answering so late!

You couldn't build a QT-Project following the instructions in this post?
I just follow this steps and I could build my projects. NetBeans will construct a makefile with all the instructions he needs (qmake included)... You don't have to do nothing.

Anònim ha dit...

Don't Worry, Your page is very clear.

Cheers.

PS. I like the poetry of your little mistake.

"A little peace of code"
instead of
"A little piece of code"

Anònim ha dit...

I will try it... thank you in advance.

Milana ha dit...

I hope you will be successfull!

Unknown ha dit...

Merci Milana, ceci fonctionne parfaitement. Bisou de France.
Thanks Milana, it works fine. Kiss from France.

Anònim ha dit...

Hi Milana,

I tried configuring Qt just as you mentioned with a difference that I was using Netbeans 6.1.

The problem is whenever I use a include code like --# include QtGui/QApplication -- the system displays an error message like "QApplication file or folder file cannot be found"

Can you please help me out with this problem.

Thanks

Anònim ha dit...

@ Topic: Nice Tutorial
@ anonym who posted befor me:
try '#include QApplication' (with brackets which I can't use here because its interpreted as html code -.-) and make sure you set the Include directories like described in the tutorial.

I just have a small question: QT makes big use of qmake, which is not used by netbeans if I'm not totally mistaken. At least if it is used I can't find it.
And thats where a problem arises. I use the Q_OBJECT functionality in one project and get the error "undefined reference to `vtable for ..." after some use of google someone mentioned to rebuild the Makefile with the help of qmake ... well ... any ideas how to attach qmake to netbeans without traveling to the moon first?

PS: ok got 2 buttons here ... bummer I can't speak a word spanish but I guess "Publiqueu EL Vostre Comentari" means "Publish comment" ... 50:50 chance