I'm trying to get a simple hello world example running, and already needed some time to figure out what includes to use Now I verified the include paths, the QApplication should actually be there, but it throws the above error. For clarity my code:
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton("Hello world!");
button->show();
return app.exec();
}
I tried compiling using first qmake -project, then qmake and finally make and then got the following errors:
qt_hello_world.o: In function 'main':
undefined reference to QApplication::QApplication(int&, char**, int)
qt_hello_world.cpp: undefined reference to QPushButton::QPushButton(QString const&, QWidget*)
qt_hello_world.cpp: undefined reference to QWidget::show()
qt_hello_world.cpp: undefined reference to QApplication::exec()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
The Makefile created by qmake contains the correct include path to the qt5 directory which contains the QtWidgets/QApplication, the QApplication file just includes the qapplication.h header that contains the actual class QApplication.
Undefined reference to ...
is a linker error, hence it is unrelated to includes, or include directories. – Huertas