Hi everyone,
I encountered an issue where visual studio complains the class declarations lacks Q_OBJECT macro.
The class definition looked something like this before:
{
Q_OBJECT
MY_CUSTOM_MACRO(Abc)
public:
Abc();
};
class Abc : QObject
{
Q_OBJECT
MY_CUSTOM_MACRO(Abc)
public:
Abc();
};
To copy to clipboard, switch view to plain text mode
Because we use the MY_CUSTOM_MACRO along with Q_OBJECT a lot, I have attempt to refactor the code so Q_OBJECT is now part of the MY_CUSTOM_MACRO. So I have changed definition of MY_CUSTOM_MACRO from this:
#define MY_CUSTOM_MACRO (E) \
public: \
void* operator new( size_t size ) \
{ \
void *storage = malloc(size); \
return storage; \
} \
private:
#define MY_CUSTOM_MACRO (E) \
public: \
void* operator new( size_t size ) \
{ \
void *storage = malloc(size); \
return storage; \
} \
private:
To copy to clipboard, switch view to plain text mode
to this:
#define MY_CUSTOM_MACRO (E) \
Q_OBJECT \
public: \
void* operator new( size_t size ) \
{ \
void *storage = malloc(size); \
return storage; \
} \
private:
#define MY_CUSTOM_MACRO (E) \
Q_OBJECT \
public: \
void* operator new( size_t size ) \
{ \
void *storage = malloc(size); \
return storage; \
} \
private:
To copy to clipboard, switch view to plain text mode
And the declaration of class Abc to this:
{
MY_CUSTOM_MACRO(Abc)
public:
Abc();
};
class Abc : QObject
{
MY_CUSTOM_MACRO(Abc)
public:
Abc();
};
To copy to clipboard, switch view to plain text mode
This is when the error of missing Q_OBJECT macro starts popping up. Does moc or something scans the header file for Q_OBJECT without expanding MY_CUSTOM_MACRO or something and hence causing the error? Or is it something else I missed?
Thuan
Bookmarks