LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   noob having problems to compile first Qt "hello world" application (https://www.linuxquestions.org/questions/programming-9/noob-having-problems-to-compile-first-qt-hello-world-application-513139/)

joakim12 12-23-2006 07:58 AM

noob having problems to compile first Qt "hello world" application
 
I'm trying to compile the next Qt code:

Code:

#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();
}

But first I had this problem:

Code:

hello.cpp:1:125: error: qapplication.h: No such file or directory
hello.cpp:2:125: error: qpushbutton.h: No such file or directory
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:6: error: ‘QApplication’ was not declared in this scope
hello.cpp:6: error: expected `;' before ‘a’
hello.cpp:7: error: ‘QPushButton’ was not declared in this scope
hello.cpp:7: error: expected `;' before ‘hello’
hello.cpp:8: error: ‘hello’ was not declared in this scope
hello.cpp:9: error: ‘a’ was not declared in this scope

Then I installed libqt4-dev with apt-get and now I'm having the next problem

Code:

joakim@leho:~/qt$ g++ -Wall -I/usr/include/qt4/Qt -L/usr/lib hello.cpp -l hello -lqt
In file included from hello.cpp:1:
/usr/include/qt4/Qt/qapplication.h:27:37: error: QtCore/qcoreapplication.h: No such file or directory
/usr/include/qt4/Qt/qapplication.h:28:31: error: QtGui/qwindowdefs.h: No such file or directory
/usr/include/qt4/Qt/qapplication.h:29:27: error: QtCore/qpoint.h: No such file or directory
/usr/include/qt4/Qt/qapplication.h:30:26: error: QtCore/qsize.h: No such file or directory
/usr/include/qt4/Qt/qapplication.h:31:27: error: QtGui/qcursor.h: No such file or directory
In file included from hello.cpp:2:
/usr/include/qt4/Qt/qpushbutton.h:27:35: error: QtGui/qabstractbutton.h: No such file or directory
/usr/include/qt4/Qt/qapplication.h:44: error: ‘QT_BEGIN_HEADER’ does not name a type
/usr/include/qt4/Qt/qapplication.h:64: error: invalid function declaration
/usr/include/qt4/Qt/qapplication.h:336: error: ‘QT_END_HEADER’ does not name a type
/usr/include/qt4/Qt/qpushbutton.h:36: error: invalid function declaration
hello.cpp:4: error: expected constructor, destructor, or type conversion before ‘int’

Are the Qt library headers installed wrongly or what is the problem?

Code:

joakim@leho:~/qt$ find /usr/ -iname qcoreapplication.h
/usr/include/qt4/Qt/qcoreapplication.h
/usr/include/qt4/QtCore/qcoreapplication.h

Thank you for your time and help.

Mara 12-23-2006 02:14 PM

Try #include <QApplication> etc.
Have you tried compiling Qt examples to make sure Qt is correctly installed?

wmakowski 12-23-2006 06:27 PM

Have you tried using qmake in the directory with the hello.cpp? Try this...

1) qmake -project
2) qmake
3) make
4) ./hello

Bill

nirucool89 06-02-2010 11:26 PM

sir,hav made the following code:

#include <QApplication>
#include <QPushButton>

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();
}

n got the same errors as my frnd joakim12 is getting...QApplication :no such file or directory etc..etc..
sir help me..how to correct these errors..i hav to make my project using Qt..waiting 4 ur reply...ASAP

MTK358 06-03-2010 08:39 AM

1. This thread is 4 years old

2. I hardly understand a word of what you said.


All times are GMT -5. The time now is 01:22 PM.