54f0733e7d
Assume an unrelated class that declares an enum and uses Q_ENUMS. Consider then a class that uses UnrelatedClass::Enum as a Q_PROPERTY. We used to include UnrelatedClass in the primary class's related meta objects, in order to support use-cases like obj->setProperty("enumProperty", "ValueOfEnumAsString"); If however moc happens to see Q_DECLARE_METATYPE(UnrelatedClass::Enum), then it would exclude it from the related meta objects, which would silently break the string based enum value conversion. This was meant as an optimization, but it isn't apparent to the developer why sometimes the string conversion would work and sometimes not (depending on whether somebody declares that macro). This also becomes visible in QML, which relies on the same embedded type information for enum assignments. This patch removes that check in moc's code generator and cleans up the code a little. However always including the prefix of Q_PROPERTY(SomePrefix::Enum ...) is not correct either, because it may be that SomePrefix is a namespace, which would cause compilation issues. Therefore we limit the inclusion of related meta objects only to Q_OBJECT decorated classes the moc has seen, and for these we save the fully qualified name in the related meta objects array (for QTBUG-2151). While this patch makes the previous workaround for namespace issues by using a Q_DECLARE_METATYPE not workable anymore, by saving the fully qualified name we are making a hopefully sufficient effort to not require a workaround in the first place. There's always the new workaround of fully qualifying the type in Q_PROPERTY. One side-effect of this change is that in the autoPropertyMetaTypeRegistration test of tst_moc, the CustomQObject for Q_PROPERTY(CustomQObject::Number enumValue ...) is now a related meta object, and therefore when querying for the type of this property via QMetaProperty::userType(), we are now aware of this being an enum and try to resolve CustomQObject::Number via QMetaType::type(qualfiedName). As there is no guarantee for this to succeed, we must now also do what is done in the non-enum code path in ::userType(), which is to call the moc generated type registration function. Task-number: QTBUG-33577 Task-number: QTBUG-2151 Change-Id: Ibf20e7421cba464c558a25c76a7e1eef002c6cff Reviewed-by: Olivier Goffart <ogoffart@woboq.com> |
||
---|---|---|
.. | ||
task71021 | ||
Test.framework/Headers | ||
testproject | ||
.gitattributes | ||
.gitignore | ||
assign-namespace.h | ||
backslash-newlines.h | ||
c-comments.h | ||
cstyle-enums.h | ||
cxx11-enums.h | ||
cxx11-explicit-override-control.h | ||
cxx11-final-classes.h | ||
dir-in-include-path.h | ||
dollars.h | ||
error-on-wrong-notify.h | ||
escapes-in-string-literals.h | ||
extraqualification.h | ||
forgotten-qinterface.h | ||
forward-declared-param.h | ||
function-with-attributes.h | ||
gadgetwithnoenums.h | ||
Header | ||
interface-from-framework.h | ||
interface-from-include.h | ||
macro-on-cmdline.h | ||
moc.pro | ||
namespaced-flags.h | ||
no-keywords.h | ||
oldstyle-casts.h | ||
os9-newlines.h | ||
parse-boost.h | ||
parse-defines.h | ||
plugin_metadata.h | ||
pp-dollar-signs.h | ||
pure-virtual-signals.h | ||
qinvokable.h | ||
qprivateslots.h | ||
related-metaobjects-in-namespaces.h | ||
single_function_keyword.h | ||
single-quote-digit-separator-n3781.h | ||
slots-with-void-template.h | ||
task87883.h | ||
task189996.h | ||
task192552.h | ||
task234909.h | ||
task240368.h | ||
template-gtgt.h | ||
trigraphs.h | ||
tst_moc.cpp | ||
unterminated-function-macro.h | ||
using-namespaces.h | ||
warn-on-multiple-qobject-subclasses.h | ||
warn-on-property-without-read.h | ||
win-newlines.h |