Q_ENUMS on C-style global enums
Hi
I'm using external headers (C-style) that have enums outside classes.
I was hoping to use the Q_ENUMS to get the strings directly, but haven't found a solution.
As it's C and no C++, the enums are global.
I cannot seem to find a way to use Q_ENUMS for global enums outside a namespace, or does anyone know a way to make it work?
cheers,
Leif
Re: Q_ENUMS on C-style global enums
I'm afraid there is simply no way to do that. Q_ENUMS registers enums to the meta-object of that particular class. There is no meta-object for the global namespace... :)
Quote:
In addition, the class defining the enum has to inherit QObject.
In fact, you can use Q_GADGET together with Q_ENUMS in a non-QObject subclass... but again, I don't think there is any solution to your problem.
Re: Q_ENUMS on C-style global enums
Thanks for the reply.
I found a solution, by modifing the header that contained the enums with something similar to this:
Code:
#ifdef QT
class MyQtAppEnums
: public QObject{
Q_OBJECT
Q_ENUMS(myenum)
public:
MyQtAppEnums (void) {};
#endif
myenum {
the = (1<<8),
number,
is,
fortytwo = 42
};
#ifdef QT
}
#endif
The above might not be 100%, but shows at least how a c style header can be kept intact for a c-compiler and make the enums a bit more qt-friendly when using moc + a c++ compiler.
thanks,
leif