c++qtenumsqgadget

Qt, enums and metaobject compiler


I have a following user class:

class MyLine : public QLineEdit
{
    Q_OBJECT

    Q_ENUMS(Base::LineState)

public:
    explicit MyLine (QWidget *parent = 0);
};

Also I have base class containing all global enums:

class Base
{
    Q_GADGET

    Q_ENUMS(LineState)

public:
    // The states for MyLine
    enum LineState
    {
        Empty, Correct, Wrong
    };
};

When I compiled this code I got a following error: undefined reference to "Base::staticMetaObject"

What need to do?


Solution

  • You don't need first Q_ENUMS(Base::LineState) in MyLine class, you are generating this meta data in Base class.

    Also you have to add header file with Base class to list of HEADERS in pro file so the moc tool could generate code for meta data.