Error when attempting to build code I copy-pasted directly from the QT for beginners wiki page.
error
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Window::Window(class QWidget *)" (??0Window@@QEAA@PEAVQWidget@@@Z) referenced in function main
debug\testempty.exe:-1: error: LNK1120: 1 unresolved externals
testempty.pro
TEMPLATE = app
TARGET = testempty
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
main.cpp \
window.cpp
HEADERS += \
window.h
window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class QPushButton;
class Window : public QWidget
{
public:
explicit Window(QWidget *parent = nullptr);
private:
QPushButton *m_button;
};
#endif // WINDOW_H
window.cpp
#include "window.h"
#include <QPushButton>
Window::Window(QWidget *parent) : QWidget(parent)
{
setFixedSize(100, 50);
m_button = new QPushButton("Hello World", this);
m_button->setGeometry(10, 10, 80, 30);
}
main.cpp
#include <QApplication>
#include "window.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
As for things I have already tried, I was instructed to build->clean all and try building again, but that made no difference.