I know that Qt4 moc was not able to do macro expanding, and now Qt5 moc can do it, at least partly.
I have macro for simple signals adding to multiple classes, lets say, for errors and warnings reports.
#define ERROR_SENDER \
signals: \
void error(Errors::ErrorCodes errorCode);
#define WARNING_SENDER \
signals: \
void warning(Warnings::WarningCodes warningCode);
#define ERROR_AND_WARNING_SENDER \
ERROR_SENDER \
WARNING_SENDER
#define ERROR_SENDER \
signals: \
void error(Errors::ErrorCodes errorCode);
#define WARNING_SENDER \
signals: \
void warning(Warnings::WarningCodes warningCode);
#define ERROR_AND_WARNING_SENDER \
ERROR_SENDER \
WARNING_SENDER
To copy to clipboard, switch view to plain text mode
And, in another header:
{
Q_OBJECT
ERROR_AND_WARNING_SENDER
...
}
class Compressor : public QObject
{
Q_OBJECT
ERROR_AND_WARNING_SENDER
...
}
To copy to clipboard, switch view to plain text mode
But it doesn't work. If I expand macro myself with simple copy-paste, it works, and signals are added in moc-generated file. But if I use macro, signals are not added in moc-generated file and it results in
./debug/compressor.o: In function `ZN10Compressor8openFileERK7QString6QFlagsIN9QIODe vice12OpenModeFlagEE':
compressor.cpp:40: undefined reference to `Compressor::error(Errors::ErrorCodes)'
How to fix it?
Bookmarks