开发者

Qt widget based on 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开发者_StackOverflow 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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜