c++ - Parameterless function in #define macro causes error despite gcc -E output being correct -
i have object store system-wide color properties has huge amount of repetitive code, such as:
q_property( qcolor backgroundcolor member m_backgroundcolor notify backgroundcolorchanged ) followed by:
qcolor m_backgroundcolor; signals: void backgroundcolorchanged(); i have hundreds of these , object difficult read , modify want replace above macro, such as:
#define color(name) public: q_property( qcolor name member m_##name notify name##changed ) signals: void name##changed(); private: qcolor m_##name; followed by
color(backgroundcolor) if run gcc -e on file gives me output expect:
public: q_property( qcolor backgroundcolor member m_backgroundcolor notify backgroundcolorchanged ) signals: void backgroundcolorchanged(); private: qcolor m_backgroundcolor; but when attempt build project, gives me following error: error: notify signal 'backgroundcolorchanged' of property 'backgroundcolor' not exist in class colors.
however, if manually copy output of gcc -e , paste header file compiles , runs no issue.
why correctly expanded macro fail build , how can fix it?
i'm afraid there no solution issue.
moc parses c++ headers signals , properties. doesn't expand macros, doesn't see signals. can see code generates error here, , there no way disable or fool check.
ideally, should fixed in moc (it should either provide option bypass check or have ability expand macros compiler does). use preprocessor expand macros file before passing header moc (this possible if use cmake, i'm not sure qmake), see overkill. recommend remove signal declaration macro , define signals explicitly.
Comments
Post a Comment