Click to See Complete Forum and Search --> : "hello world" qt problem


cjanscen
10-04-2003, 11:49 PM
I know I am doing something really stupid (and really small), but I don't know what!? Why does this not compile:


#include <qapplication.h>
#include <qpushbutton.h>

int main( int argc, char **argv ) {
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
a.setMainWidget( &hello );
hello.show();
return a.exec(); }


I do this:
g++ ./main.cpp
It does this:


main.cpp:1:26: qapplication.h: No such file or directory
main.cpp:2:25: qpushbutton.h: No such file or directory
main.cpp: In function `int main(int, char**)':
main.cpp:7: `QApplication' undeclared (first use this function)
main.cpp:7: (Each undeclared identifier is reported only once for each function it appears in.) main.cpp:7: syntax error before `(' token main.cpp:9: `QPushButton' undeclared (first use this function) main.cpp:10: `hello' undeclared (first use this function)
main.cpp:12: `a' undeclared (first use this function)

serz
10-04-2003, 11:52 PM
main.cpp:1:26: qapplication.h: No such file or directory
main.cpp:2:25: qpushbutton.h: No such file or directory

Probably because it's not finding those.

solar_gateway
10-05-2003, 03:31 AM
i have the same problem!

are you using mandrake 9.1??

anyway 'Bwkaz' will help you out im sure!

bwkaz
10-05-2003, 02:41 PM
Originally posted by cjanscen
I do this:
g++ ./main.cpp You should also be passing the correct include path to g++. Later on, it'll also need the correct library path, and the directive telling it to link against libqt.so (or libqt-mt.so).

First, find qapplication.h. On my system, it's in /usr/qt3/include/, but it almost assuredly won't be there for you. If you have the shell variable $QTDIR set (if echo $QTDIR prints anything, then it is set), then you can use $QTDIR/include, but if it's not, you'll have to go searching.

Then, tell g++ to use the directory that qapplication.h resides in, as an include directory. To do that, put the directory name after the -I switch (capital i), like this:

g++ -I$QTDIR/include main.cpp

Now, this still won't work, but it should get around the errors you quoted. You'll probably get a bunch of "undefined symbol" errors from the linker. The way to fix that is to add -L$QTDIR/lib to the command line, and then also add -lqt (that's a lowercase ell) or -lqt-mt if g++ complains that it "can't find -lqt".

If course, $QTDIR has to be set to be able to do it this way. If it's not set, then you'll have to basically guess, based on where you found qapplication.h.