简体   繁体   中英

QObject error with macro and include

I want to use signal and slot in my program and for this I am told Ineed to add Q_OBJECT as below.

Well I have a class:

class A
{
    Q_OBJECT
public:
    A();
};

This gives an error which says 'Q_OBJECT does not name a type'. If I than add #include It give the error 'undefined reference to vtable of A'

So what is the right way to do this?

The Q_OBJECT macro is meant for subclasses of a QObject (or other subclasses). It is also required if you want your class to use signals and slots.

class A 
    : public QObject
{
    Q_OBJECT

 public:
    A(QObject *parent = 0);
};

Q_OBJECT

The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.
...
Note:
This macro requires the class to be a subclass of QObject. ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM