2011-10-25 04:42:16 +00:00
|
|
|
CONFIG += testcase
|
|
|
|
TARGET = tst_moc
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#exists(/usr/include/boost/spirit.hpp) {
|
|
|
|
# message("including boost headers in test")
|
|
|
|
# DEFINES += PARSE_BOOST
|
|
|
|
# # need to add explicitly so that it ends up in moc's search path
|
|
|
|
# INCLUDEPATH += /usr/include
|
|
|
|
#}
|
|
|
|
|
|
|
|
INCLUDEPATH += testproject/include testproject
|
|
|
|
|
|
|
|
cross_compile: DEFINES += MOC_CROSS_COMPILED
|
|
|
|
|
|
|
|
HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-newlines.h oldstyle-casts.h \
|
|
|
|
slots-with-void-template.h qinvokable.h namespaced-flags.h trigraphs.h \
|
|
|
|
escapes-in-string-literals.h cstyle-enums.h qprivateslots.h gadgetwithnoenums.h \
|
2019-12-05 13:05:11 +00:00
|
|
|
dir-in-include-path.h single_function_keyword.h task192552.h \
|
2012-03-05 16:55:59 +00:00
|
|
|
task234909.h task240368.h pure-virtual-signals.h cxx11-enums.h \
|
|
|
|
cxx11-final-classes.h \
|
2012-07-10 16:08:18 +00:00
|
|
|
cxx11-explicit-override-control.h \
|
2012-09-03 10:55:38 +00:00
|
|
|
forward-declared-param.h \
|
2012-10-01 09:57:53 +00:00
|
|
|
parse-defines.h \
|
2013-08-20 07:02:17 +00:00
|
|
|
function-with-attributes.h \
|
2013-10-25 15:00:17 +00:00
|
|
|
plugin_metadata.h \
|
Fix erroneous exclusion of classes from related meta objects in moc
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>
2013-12-12 09:50:00 +00:00
|
|
|
single-quote-digit-separator-n3781.h \
|
2013-12-23 14:16:08 +00:00
|
|
|
related-metaobjects-in-namespaces.h \
|
|
|
|
qtbug-35657-gadget.h \
|
2015-01-12 14:55:13 +00:00
|
|
|
non-gadget-parent-class.h grand-parent-gadget-class.h \
|
2014-01-17 17:25:50 +00:00
|
|
|
related-metaobjects-in-gadget.h \
|
2016-08-23 19:32:11 +00:00
|
|
|
related-metaobjects-name-conflict.h \
|
2018-11-05 12:44:30 +00:00
|
|
|
namespace.h cxx17-namespaces.h \
|
2020-01-03 14:03:39 +00:00
|
|
|
cxx-attributes.h \
|
|
|
|
moc_include.h
|
2012-03-05 16:55:59 +00:00
|
|
|
|
2018-12-17 14:09:23 +00:00
|
|
|
# No platform specifics in the JSON files, so that we can compare them
|
|
|
|
JSON_HEADERS = $$HEADERS
|
|
|
|
JSON_HEADERS -= cxx-attributes.h
|
2012-03-05 16:55:59 +00:00
|
|
|
|
2017-10-01 01:19:36 +00:00
|
|
|
if(*-g++*|*-icc*|*-clang*|*-llvm):!win32-*: HEADERS += os9-newlines.h win-newlines.h
|
2013-03-01 14:06:33 +00:00
|
|
|
if(*-g++*|*-clang*): HEADERS += dollars.h
|
2011-04-27 10:05:43 +00:00
|
|
|
SOURCES += tst_moc.cpp
|
|
|
|
|
2017-01-09 10:39:46 +00:00
|
|
|
QT = core testlib
|
|
|
|
qtHaveModule(dbus): QT += dbus
|
|
|
|
qtHaveModule(concurrent): QT += concurrent
|
|
|
|
qtHaveModule(network): QT += network
|
|
|
|
qtHaveModule(sql): QT += sql
|
2013-08-20 07:02:17 +00:00
|
|
|
|
|
|
|
# tst_Moc::specifyMetaTagsFromCmdline()
|
|
|
|
# Ensure that plugin_metadata.h are moc-ed with some extra -M arguments:
|
|
|
|
QMAKE_MOC_OPTIONS += -Muri=com.company.app -Muri=com.company.app.private
|
|
|
|
|
2013-09-25 19:36:15 +00:00
|
|
|
# Define macro on the command lines used in parse-defines.h
|
|
|
|
QMAKE_MOC_OPTIONS += "-DDEFINE_CMDLINE_EMPTY=" "\"-DDEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)\""
|
|
|
|
|
2018-12-17 14:09:23 +00:00
|
|
|
QMAKE_MOC_OPTIONS += --output-json
|
|
|
|
|
|
|
|
debug_and_release {
|
|
|
|
CONFIG(debug, debug|release) {
|
|
|
|
MOC_CPP_DIR = $$MOC_DIR/debug
|
|
|
|
} else {
|
|
|
|
MOC_CPP_DIR = $$MOC_DIR/release
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOC_CPP_DIR = $$MOC_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
moc_json_header.input = JSON_HEADERS
|
|
|
|
moc_json_header.output = $$MOC_CPP_DIR/$${QMAKE_H_MOD_MOC}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_CPP)}.json
|
|
|
|
moc_json_header.CONFIG = no_link moc_verify
|
|
|
|
moc_json_header.depends = $$MOC_CPP_DIR/$${QMAKE_H_MOD_MOC}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_CPP)}
|
|
|
|
moc_json_header.commands = $$escape_expand(\\n) # force creation of rule
|
|
|
|
moc_json_header.variable_out = MOC_JSON_HEADERS
|
|
|
|
|
|
|
|
BASELINE_IN = allmocs_baseline_in.json
|
|
|
|
copy_baseline.commands = $${QMAKE_COPY} $$shell_path(${QMAKE_FILE_NAME}) ${QMAKE_FILE_OUT}
|
|
|
|
copy_baseline.input = BASELINE_IN
|
|
|
|
copy_baseline.output = $$OUT_PWD/allmocs_baseline.json
|
|
|
|
copy_baseline.CONFIG = no_link
|
|
|
|
|
|
|
|
qtPrepareTool(MOC_COLLECT_JSON, moc)
|
|
|
|
jsoncollector.CONFIG += combine
|
|
|
|
jsoncollector.commands = $$MOC_COLLECT_JSON --collect-json -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
|
|
|
|
jsoncollector.input = MOC_JSON_HEADERS
|
|
|
|
jsoncollector.output = $$OUT_PWD/allmocs.json
|
|
|
|
jsoncollector.variable_out = GENERATED_FILES
|
|
|
|
|
|
|
|
allmocs_contents = \
|
|
|
|
"<!DOCTYPE RCC><RCC version=\"1.0\">"\
|
|
|
|
"<qresource prefix=\"/\">"\
|
|
|
|
"<file>allmocs.json</file>"\
|
|
|
|
"<file>allmocs_baseline.json</file>"\
|
|
|
|
"</qresource>"\
|
|
|
|
"</RCC>"
|
|
|
|
|
|
|
|
allmocs_file = $$OUT_PWD/allmocs.qrc
|
|
|
|
|
|
|
|
!write_file($$allmocs_file, allmocs_contents): error()
|
|
|
|
RESOURCES += $$allmocs_file
|
|
|
|
|
|
|
|
QMAKE_EXTRA_COMPILERS += moc_json_header copy_baseline jsoncollector
|