Qt widget based on QWidget

I am trying to create my own QWidget based widget. In the constructor of class i:

Square(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);

Square::Square(QWidget *parent = 0, const char *name = 0, WFlags fl)
        : QWidget(parent, name, f)
{
        if (!name)
                setName("Game");
        reset();
        underMouse=false;
}

But I see an error: 'WFlags is not declared

Now I will redo my code:

class Square : public QWidget
{
    Q_OBJECT

    public:
        Square(QWidget *parent = 0);
};

and squared .cpp:

Square::Square(QWidget *parent)
        : QWidget(parent)
{
}

But I see an error:

  • error: undefined reference to `vtable for Square '

  • error: collect2: ld returned 1 exit status What is wrong? How can I declare a constructor of a QWidget based class?

Thank.

+3
source share
1 answer

If you use Qt4, the compiler is absolutely right. WFlagsnot announced. That Qt::WindowFlags. Plus you don't need to name- this is a Qt3 thing.

See http://doc.qt.io/archives/4.6/qwidget.html#QWidget

, WindowFlags . Qt, (, http://doc.qt.io/archives/4.6/qpushbutton.html#QPushButton).

+8

Source: https://habr.com/ru/post/1770333/


All Articles