Skip to content

Commit

Permalink
qt library: Make Q_PROPERTY a variadic macro to avoid preprocessorErr…
Browse files Browse the repository at this point in the history
…orDirective (#5370)

Treat Q_PROPERTY as variadic macro to avoid preprocessorErrorDirective
with associative container templates itroducing a "," like for example
`QHash<QString, int>`. Using templates is totally fine in the context of
a moc compiler.

The macro Q_PROPERTY is defined as variadic in
qobjectdefs.h/qtmetaobject.h when not compiling using the moc compiler.

See following references:
* For Qt 5.15
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h?h=5.15#n104
* For Qt 6.6
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qtmetamacros.h?h=6.6#n5
  • Loading branch information
vb-linetco committed Aug 25, 2023
1 parent 74ad724 commit 078e967
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cfg/qt.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5084,7 +5084,8 @@
<define name="Q_OBJECT" value=""/>
<define name="Q_PRIVATE_SLOT(d, signature)" value=""/>
<define name="Q_SLOTS" value=""/>
<define name="Q_PROPERTY(X)" value=""/>
<!-- Treat as variadic macro to avoid preprocessorErrorDirective -->
<define name="Q_PROPERTY(...)" value=""/>
<define name="Q_Q(Class)" value="Class * const q = q_func()"/>
<define name="Q_RETURN_ARG(type, data)" value="QReturnArgument&lt;type &gt;(#type, data)"/>
<define name="Q_UNLIKELY(expr)" value="expr"/>
Expand Down
6 changes: 6 additions & 0 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,10 @@ namespace {
// simplifyQtSignalsSlots2
namespace Foo { class Bar; }
class Foo::Bar : public QObject { private slots: };

// Q_PROPERTY with templates inducing a ',' should not produce a preprocessorErrorDirective
class AssocProperty : public QObject {
public:
Q_PROPERTY(QHash<QString, int> hash READ hash WRITE setHash)
};
}

0 comments on commit 078e967

Please sign in to comment.