Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt for begginers :10 subclassing Qt widget .
Hello , I have a problem . It can not link .
main.obj:-1: ошибка: LNK2019: unresolved external symbol "public: __cdecl Window::Window(class QWidget *)" (??0Window@@QEAA@PEAVQWidget@@@Z) referenced in function main
Can some one help me ?
Hi, welcome to devnet.
Apparently you have not defined a constructor for your class Window.
I copy and insert text in my project , I cant understand why this dont work =\
int main(int argc, char **argv)
QApplication app (argc, argv);
As I said - apparently you haven't defined a constructor for your Window class. Can you show Window.h and Window .cpp files?
class Window : public QWidget
explicit Window(QWidget *parent = 0);
#endif // WINDOW_H
Window::Window(QWidget *parent) :
// Set size of the window
// Create and position the button
m_button = new QPushButton("Hello World", this);
m_button->setGeometry(10, 10, 80, 30);
Ok, these seem fine. So if the linker can't see the constructor then it means the compiler didn't compile the Window.cpp file. Can you confirm you added it in your project file (.pro) and re-run qmake?
Btw. When pasting code in the forum surround it with ``` (three backticks). This will format it for better reading.
I have : main.cpp , Qt1.pro , window.cpp and window.h files . I dont know re-run qmake , Im begginer .
The project file is Qt1.pro. This is where you define which files are part of your project. There should be a section in it looking like this:
HEADERS += window.h SOURCES += main.cpp \ window.cpp
The error you pasted can mean you're missing the window.cpp file from the SOURCES section.
After you add it there (if it's missing) re-run qmake (it's a tool that reads this .pro file and generates makefiles for your compiler). You do that by clicking "run qmake" in the "Build" menu in Qt Creator.
Thank you , "Run Qmake" work =) I use only green triangle >.< Now all work .
Great. You only need to run qmake when you change the contents of the project file.