Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt widget based on QWidget

Tags:

c++

qt

qwidget

I try to create my own widget based in QWidget. In constructor of the class i have:

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 error: ‘WFlags’ has not been declared

Now i remade my code:

class Square : public QWidget
{
    Q_OBJECT

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

and in square.cpp:

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

But i see error:

  • error: undefined reference to `vtable for Square'

  • error: collect2: ld returned 1 exit status What's wrong? How can i declare constructor of the class based in QWidget?

Thank you.

like image 576
0xAX Avatar asked Jan 21 '23 06:01

0xAX


1 Answers

If you're using Qt4, the compiler is absolutely right. WFlags has not been declared. It's Qt::WindowFlags. Also, you don't need name -- that's a Qt3 thing.

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

By the way, I never bother to allow passing WindowFlags through my constructors. If you look at the standard Qt widgets, they don't either (e.g. http://doc.qt.io/archives/4.6/qpushbutton.html#QPushButton).

like image 143
Steve S Avatar answered Feb 01 '23 18:02

Steve S