From d49e7acc2bb98ae9416a532dac1f18e972fffb88 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 16 Aug 2014 11:36:48 +0200 Subject: moc: Have a staticMetaCall in the Q_GADGET metaobject This provides a way to invoke Q_INVOKABLE method Change-Id: I301cec2a21c2889fb9dde0b1eb6e92d0bd561bd7 Reviewed-by: Simon Hausmann --- src/tools/moc/generator.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index dd032e46f6..b9c46300e4 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -425,7 +425,8 @@ void Generator::generateCode() // // Generate internal qt_static_metacall() function // - if (cdef->hasQObject && !isQt) + const bool hasStaticMetaCall = (cdef->hasQObject || !cdef->methodList.isEmpty()) && !isQt; + if (hasStaticMetaCall) generateStaticMetacall(); // @@ -513,7 +514,7 @@ void Generator::generateCode() fprintf(out, "qt_meta_stringdata_%s.data,\n" " qt_meta_data_%s, ", qualifiedClassNameIdentifier.constData(), qualifiedClassNameIdentifier.constData()); - if (cdef->hasQObject && !isQt) + if (hasStaticMetaCall) fprintf(out, " qt_static_metacall, "); else fprintf(out, " 0, "); @@ -1246,10 +1247,14 @@ void Generator::generateStaticMetacall() else fprintf(out, " "); fprintf(out, "if (_c == QMetaObject::InvokeMetaMethod) {\n"); + if (cdef->hasQObject) { #ifndef QT_NO_DEBUG - fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); + fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); #endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + } else { + fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + } fprintf(out, " switch (_id) {\n"); for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) { const FunctionDef &f = methodList.at(methodindex); -- cgit v1.2.3