[Development] QQmlListProperty<T>: static_assert that T inherits QObject
milian.wolff at kdab.com
Fri Jan 27 00:20:46 CET 2017
the QQmlListProperty states:
"Note: QQmlListProperty can only be used for lists of QObject-derived object
Since I am bad at reading documentation, I previously tried (I think multiple
times) to do something like:
This happily compiles and only at runtime does it not work. So I thought I'd
add a static assert to QQmlListProperty to check this at compile time:
But this uncovered this gem inside qtdeclarative itself:
158: QQmlListProperty<void> _currentList;
Uhm, a void* list, really? Should this be a QQmlListProperty<QObject>?
Digging further, I find a few places where QQmlListProperty<T> is instantiated
for non-QObjects, mostly within qmlRegisterUncreateableType, which is easy to
prevent by leveraging std::enable_if.
Digging even further, I hit the first road-block though with my approach:
Adding the static assert directly to QQmlListProperty means that T must be
fully defined when the list property gets used. Does this make this change
source-incompatible? Is there a workaround for this? I fixed the issues inside
Qt Declarative itself, but I wonder whether this is acceptable for existing
users of QQmlListProperty outside of QtDeclarative.
The second road-block comes when compiling the tests - apparently
QQmlListProperty also works with interfaces! So I added another type trait for
that. Is that acceptable?
Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
KDAB - The Qt Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 5903 bytes
Desc: not available
More information about the Development