Search code examples
c++eclipsemacroseclipse-cdt

Eclipse - how to define macros (not merely symbols) to resolve to empty


Qt-specific macros break my Eclipse C++ indexing.

In my Qt classes, I'll have something like:

Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)

For the purpose of indexing, I'd like for Q_PROPERTY() to resolve to empty statement meaning I want

#define Q_PROPERTY() /* blank */

I know how to make macros resolve to simple values using Eclipse:

C/C++ General > Paths and Symbols > Symbols

QUESTION

Within Eclipse, i.e. without creating a separate header that I include solely for indexing, is it possible to define macros to resolve to something else (in my case "empty")?


Solution

  • You can define both object-style and function-style macros in C/C++ General > Paths and Symbols > Symbols.

    For example, to define your desired

    #define Q_PROPERTY() /* blank */
    

    macro, in the "Add symbol" dialog, enter Q_PROPERTY() under "Name", and /* blank */ under "Value".

    Note that, if your intention is to have CDT ignore Qt Q_PROPERTY declarations, you actually want Q_PROPERTY(...) as the name, since the macro takes arguments (Q_PROPERTY() would only match macro calls with no arguments).