I am learning how to use Qt. I am in the middle of the beginner's tutorials, and I ran into a problem.
I have this class here:
#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
I know the purpose of any row but this one:
class QPushButton;
In my all years I learned cpp, I never encountered this such a thing. I know that when I want to declare a class, I have to do this with this basic template:
class ClassName:
{
public:
//Optional public.
private:
//Optional private.
}
But one row declaration?
I want to ask more then that:
- Why do the Qt guys work like this?
- Why don't they
#include"
theQPushButton
in the header?
They included this button class within the implementation. Why?:
#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);
}