tags:

views:

79

answers:

1

Hello,

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.

+6  A: 

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.nokia.com/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.nokia.com/4.6/qpushbutton.html#QPushButton).

Steve S