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.
The tutorial https://wiki.qt.io/Qt_for_Beginners is fully updated so you must modify it. Change to:
TEMPLATE = app
TARGET = callboot-ui.exe
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
HEADERS +=
SOURCES += main.cpp
In the case of @jww it has an error in the following line of the .pro:
greaterThan(QT_MAJOR_VERSION, 5): QT += core gui widgets
The error is caused because greaterThan(QT_MAJOR_VERSION, 5)
verifies that the major version of Qt is greater than 5 to add sub-modules, but the latest version of Qt is 5.13.2 is not greater than 5, so it is not linked the modules causing the error shown.
In the tutorial greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
is used to support .pro so that it can be compiled for Qt4 and Qt5 since in the latter the widgets moved to a new sub-module called widgets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With