[Development] QQmlListProperty<T>: static_assert that T inherits QObject

Milian Wolff milian.wolff at kdab.com
Fri Jan 27 00:20:46 CET 2017


Hey all,

the QQmlListProperty states:

"Note: QQmlListProperty can only be used for lists of QObject-derived object 
pointers."

Since I am bad at reading documentation, I previously tried (I think multiple 
times) to do something like:

QQmlListProperty<MyGadget>

or even

QQmlListProperty<NeitherQObjectNorQGadget>

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:

https://codereview.qt-project.org/#/c/183631/

But this uncovered this gem inside qtdeclarative itself:

qqmlobjectcreator_p.h:
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?

Thanks

-- 
Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5903 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170127/63a3fe43/attachment.bin>


More information about the Development mailing list