Qt for begginers :10 subclassing Qt widget .
-
Hi, welcome to devnet.
Apparently you have not defined a constructor for your class Window.
-
As I said - apparently you haven't defined a constructor for your Window class. Can you show Window.h and Window .cpp files?
-
//window.h
#ifndef WINDOW_H
#define WINDOW_H#include <QWidget>
class QPushButton;
class Window : public QWidget
{
public:
explicit Window(QWidget *parent = 0);
private:
QPushButton *m_button;
};#endif // WINDOW_H
//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);
} -
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.
-
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. -
Great. You only need to run qmake when you change the contents of the project file.