# Trying to compile a simple qt program



## geek_nomad (May 16, 2010)

I installed qt4 through ports. I followed the tutorials from the qt assistant. I'm finding it difficult to compile the program.
Here's the code for the program..

```
#include <QtGui>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
     QWidget window;
     window.resize(320, 240);
     window.show();
     window.setWindowTitle(
         QApplication::translate("toplevel", "Top-level widget"));
     return app.exec();
 }
```


When i try to compile, i get the following errors..


```
c++ -c -pipe -Wall -W -O2 -pipe -fno-strict-aliasing -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/local/share/qt/mkspecs/freebsd-g++ -I. -I. -I/usr/local/include -I/usr/local/include/qt4/include -o window.o window.cpp
window.cpp:1:17: error: QtGui: No such file or directory
window.cpp: In function 'int main(int, char**)':
window.cpp:5: error: 'QApplication' was not declared in this scope
window.cpp:5: error: expected `;' before 'app'
window.cpp:6: error: 'QWidget' was not declared in this scope
window.cpp:6: error: expected `;' before 'window'
window.cpp:7: error: 'window' was not declared in this scope
window.cpp:10: error: 'QApplication' is not a class or namespace
window.cpp:11: error: 'app' was not declared in this scope
window.cpp: At global scope:
window.cpp:3: warning: unused parameter 'argc'
window.cpp:3: warning: unused parameter 'argv'
*** Error code 1

Stop in /home/Dipesh/cpp/qt.
```

I know i am supposed to add some environment variables before i compile a qt program. These are environment variables i've added related to qt..


```
QTDIR=/usr/local/include/qt4
QMAKESPEC=freebsd-g++
```

What should i do?


----------



## OH (May 16, 2010)

What commands did give to compile this program? More specifically: did you use qmake-qt4?


----------



## geek_nomad (May 16, 2010)

nope. i first gave qmake and then make. thats when i got these errors.
And i think because of this problem, i'm having troubles in compiling kde4 from ports.


----------



## expl (May 16, 2010)

You either have to change your include to 
	
	



```
<QtGui/QtGui>
```
 or add 
	
	



```
-I/usr/local/include/qt4/QtGui
```
 to gcc.


----------



## OH (May 16, 2010)

Use these commands to build, no other adjustments should be neccesary:
`$ qmake-qt4 -project`
(ignore QFileInfo notice, if any)
`$ qmake-qt4`
`$ make`


----------

