error LNK2019: unresolved external symbol
-
wrote on 16 Nov 2016, 19:47 last edited by
Hi,
As a beginner I read Qt for Beginners. All works well until point 10 Subclassing QWidget. When I enter code and try to compile I get 'error LNK2019: unresolved external symbol "public: __thiscall Window::Window(class QWidget *)" (??0Window@@QAE@PAVQWidget@@@Z) referenced in function _main'.
How do I solve the error?
/Jonny -
Hi,
As a beginner I read Qt for Beginners. All works well until point 10 Subclassing QWidget. When I enter code and try to compile I get 'error LNK2019: unresolved external symbol "public: __thiscall Window::Window(class QWidget *)" (??0Window@@QAE@PAVQWidget@@@Z) referenced in function _main'.
How do I solve the error?
/JonnyHi,
js6033 said in error LNK2019: unresolved external symbol:
How do I solve the error?
It's basic C++ and has little to do with Qt. You need to provide a body for the class' constructor. You have provided only declaration and when the linker runs it can't find the symbol so it complains.
Kind regards.
-
wrote on 16 Nov 2016, 21:54 last edited by
But what should I do? I am reading tutorial for beginner and enter code exactly as in the tutorial.
-
Hi,
Which tutorial is it ?
-
wrote on 16 Nov 2016, 22:18 last edited by
Show us the code and compile/link command and we can tell ya what's wrong. :)
-
wrote on 16 Nov 2016, 22:28 last edited by
tutorial at https://wiki.qt.io/Qt_for_Beginners
down to point 10 Subclassing QWidget are the codes. -
tutorial at https://wiki.qt.io/Qt_for_Beginners
down to point 10 Subclassing QWidget are the codes.@js6033 said in error LNK2019: unresolved external symbol:
tutorial at https://wiki.qt.io/Qt_for_Beginners
down to point 10 Subclassing QWidget are the codes.Do you have:
Window::Window(QWidget *parent) : QWidget(parent) { // ... }
in your cpp file?
-
wrote on 16 Nov 2016, 22:36 last edited by
This was taken from that tutorial:
window.cpp #include "window.h" #include <QPushButton> Window::Window(QWidget *parent) : QWidget(parent) { // Set size of the window setFixedSize(100, 50); // Create and position the button m_button = new QPushButton("Hello World", this); m_button->setGeometry(10, 10, 80, 30); }
If you have that window.cpp file and the code is in it like that then you just didn't include it in your build.
Make sure that the window.cpp file is being built and linked to the main executable in your project.
-
wrote on 25 May 2017, 12:19 last edited by
Delete previously created files from the build, And then run again.