PDA

View Full Version : Qt code won't compile, not including correct files.


caesius
December 27th, 2009, 10:33
I delving into Qt4 GUI programming, but I can't compile this:

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QPushButton hello("Hello world!");
hello.resize(100, 30);

hello.show();
return app.exec();
}

the error is:

> gcc -o qt qt.cpp
qt.cpp:1:24: error: QApplication: No such file or directory
qt.cpp:2:23: error: QPushButton: No such file or directory
qt.cpp: In function 'int main(int, char**)':

[BLAH BLAH BLAH]
>

but even when I explicitly give the include paths:

//#include <QApplication>
#include "/usr/local/include/qt4/QtGui/QApplication"
//#include <QPushButton>
#include "/usr/local/include/qt4/QtGui/QPushButton"

I get this:

> gcc -o qt qt.cpp
In file included from /usr/local/include/qt4/QtGui/QApplication:1,
from qt.cpp:2:
/usr/local/include/qt4/QtGui/qapplication.h:45:37: error: QtCore/qcoreapplication.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:46:31: error: QtGui/qwindowdefs.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:47:27: error: QtCore/qpoint.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:48:26: error: QtCore/qsize.h: No such file or directory

[CLIPPED THE REST, YOU GET THE POINT]


I *know*, I could probably use qmake to build this, but the inquisitive part of me is jumping out; it's still just a C++ program, why can't I compile it?

Thanks for any nudges in the right direction.

expl
December 27th, 2009, 10:55
Try compiling like this:
g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -L/usr/local/lib/qt4 -lQtGui -lQtCore -o qt qt.cpp

ta0kira
January 6th, 2010, 04:15
Try compiling like this:
g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -L/usr/local/lib/qt4 -lQtGui -lQtCore -o qt qt.cppIf /usr/local/lib/qt4 isn't in a path that ldconfig checks (extremely likely) the compiled program might not run without preceding the Qt libs with -Xlinker -rpath /usr/local/lib/qt4. Explicitly naming the Qt libraries by full path-name might be better.
Kevin Barry

SIFE
January 31st, 2011, 18:15
Even this thread is old, I put this just for knowing the cause of problem.
#qmake-qt4 -project
#qmake-qt4
#make
This is for QT4, if you use QT3 try this:
#qmake -project
#qmake
#make