LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can't compile Qt project (https://www.linuxquestions.org/questions/programming-9/cant-compile-qt-project-768219/)

MTK358 11-10-2009 12:06 PM

Can't compile Qt project
 
I installed the Qt libraries and wrote a small sample program, but when I try compiling it it does this:

Code:

$ qmake -project
$ qmake
$ make
g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT  -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o qtorial.o qtorial.cpp
qtorial.cpp:1:24: error: QApplication: No such file or directory
qtorial.cpp:2:23: error: QPushButton: No such file or directory
qtorial.cpp: In function ‘int main(int, char**)’:
qtorial.cpp:6: error: ‘QApplication’ was not declared in this scope
qtorial.cpp:6: error: expected `;' before ‘app’
qtorial.cpp:7: error: ‘QPushButton’ was not declared in this scope
qtorial.cpp:7: error: expected `;' before ‘hello’
qtorial.cpp:8: error: ‘hello’ was not declared in this scope
qtorial.cpp:9: error: ‘app’ was not declared in this scope
qtorial.cpp: At global scope:
qtorial.cpp:4: warning: unused parameter ‘argc’
qtorial.cpp:4: warning: unused parameter ‘argv’
make: *** [qtorial.o] Error 1

This is the second time I tried Qt programming and I always get this.
I wonder what's the problem?

This is the code:

Code:

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
        QApplication app(argc, argv);
        QPushButton hello("Hello, World!");
        hello.show();
        return app.exec();
}


ozanbaba 11-10-2009 12:21 PM

Quote:

Originally Posted by MTK358 (Post 3751826)
I installed the Qt libraries and wrote a small sample program, but when I try compiling it it does this:

Code:

$ qmake -project
$ qmake
$ make
g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT  -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o qtorial.o qtorial.cpp
qtorial.cpp:1:24: error: QApplication: No such file or directory
qtorial.cpp:2:23: error: QPushButton: No such file or directory
qtorial.cpp: In function ‘int main(int, char**)’:
qtorial.cpp:6: error: ‘QApplication’ was not declared in this scope
qtorial.cpp:6: error: expected `;' before ‘app’
qtorial.cpp:7: error: ‘QPushButton’ was not declared in this scope
qtorial.cpp:7: error: expected `;' before ‘hello’
qtorial.cpp:8: error: ‘hello’ was not declared in this scope
qtorial.cpp:9: error: ‘app’ was not declared in this scope
qtorial.cpp: At global scope:
qtorial.cpp:4: warning: unused parameter ‘argc’
qtorial.cpp:4: warning: unused parameter ‘argv’
make: *** [qtorial.o] Error 1

This is the second time I tried Qt programming and I always get this.
I wonder what's the problem?

This is the code:

Code:

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
        QApplication app(argc, argv);
        QPushButton hello("Hello, World!");
        hello.show();
        return app.exec();
}


no Headers? it does seem to me as no headers are installed. try looking for devel or dev packages which should have the headers and any other need files for compiling.

MTK358 11-10-2009 12:24 PM

This is what I downloaded (the Framework Only section):

http://qt.nokia.com/downloads

ozanbaba 11-10-2009 01:45 PM

Quote:

Originally Posted by MTK358 (Post 3751842)
This is what I downloaded (the Framework Only section):

http://qt.nokia.com/downloads

did you installed it from source as make && make install (not the actual command), if so it should have installed header files. maybe gcc can't find headers as they are installed in none default place or gcc gets wrong flags. check the makefile used for the compile.

and check this folder /usr/include/qt3. and isn't there a official or none-official qt package for your system?

MTK358 11-10-2009 01:51 PM

I installed like this, just like you said (Note that I shut down the computer between the two, make took longer than I expected and it was quite late by then, but I don't think this could have affected anything):

Code:

$ make
$ make install

I do have a /usr/include/qt3 folder, and it seems to be full of header files (.h).

nadroj 11-10-2009 02:49 PM

I dont know anything about Qt, but use these instead of the headers you have (which, as the compiler says, dont exist)
Code:

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


MTK358 11-10-2009 03:02 PM

Same thing.

But anyway it shows the headers capitalized everywhere.

nadroj 11-10-2009 03:10 PM

No, it doesnt.

Apparently Qt 4 uses what you had in your first post (see http://doc.trolltech.com/4.0/tutorial-t1.html). However, your using Qt 3 which does what I suggested (see http://doc.trolltech.com/3.0/tutorial1-01.html). Make sure you followed the steps for Qt 3, for installation, configuration, compiling, etc, as it seems you followed the Qt 4 Hello World tutorial its possible you followed the Qt 4 version of other steps.

ozanbaba 11-10-2009 03:28 PM

Quote:

Originally Posted by nadroj (Post 3751992)
I dont know anything about Qt, but use these instead of the headers you have (which, as the compiler says, dont exist)
Code:

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


i was just gonna say this. probably this is why gcc can't find it. however in C++, #include<QApplication> style includes. maybe we can't use gcc rightly.

and MTK358, i tried it with QT4 and it worked. maybe you are using wrong version of qt to compile.

qmake -v should show you the QT version and where it is.

you are trying to complite it with QT3.

nadroj 11-10-2009 03:35 PM

Quote:

i was just gonna say this. probably this is why gcc can't find it
He/she is using g++, not gcc. And my guess, as mentioned above, is that he/she followed the wrong tutorial/setup/configuration guide (used Qt 4 instead of Qt 3, as he/she did for the tutorial).

ozanbaba 11-10-2009 03:54 PM

Quote:

Originally Posted by nadroj (Post 3752045)
He/she is using g++, not gcc. And my guess, as mentioned above, is that he/she followed the wrong tutorial/setup/configuration guide (used Qt 4 instead of Qt 3, as he/she did for the tutorial).

gcc is umbrella term for Gnu Compiler Collection (GCC).

and definitely she is using wrong QT version.

MTK358 11-10-2009 04:10 PM

But the page where I downloaded it says Qt4!?!

Anyway it didn't work and then I tried apt-get install qt-dev*, maybe that's the problem.

Also I am going to get openSUSE 11.2 tomorrow, and I hope to install it instead of Debian. I would really want to know how to install Qt4 (not 3) correctly there and have it work.

But it would be nice to get some Qt practice on Debian toworrow while waiting for the approximately 4.7GB download.

I see you are wondering whether I am a "he" or a "she", I am a "he".

MTK358 11-10-2009 05:24 PM

It does work Qt3 style.

nadroj 11-10-2009 05:26 PM

Quote:

Originally Posted by nadroj (Post 3751992)
I dont know anything about Qt, but use these instead of the headers you have (which, as the compiler says, dont exist)
Code:

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


So this is the correct way?

MTK358 11-10-2009 07:24 PM

Yes. At least for Qt3, as far as I know.


All times are GMT -5. The time now is 11:53 AM.