summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/generator.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2011-10-31 15:22:31 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-14 15:52:26 +0100
commit49bd825a9626eda77fd9e8313e1868bed4c77bff (patch)
tree586101b058be0f70014157c3185504cf65127d2e /src/tools/moc/generator.cpp
parente9c7edddb58bb69a29e75712adfa059dcfcc71fd (diff)
moc: support mapping pointers to member functions to indexes
This change adds QMetaObject::IndexOfMethod as a parameter to the qt_static_metacall function. It lets the moc generated code return the index of a signal or slot given its pointer to member function This is required to support the new connection syntax Change-Id: I39198c6699b5aa3599d3d282f7ac79b1e3684d33 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/tools/moc/generator.cpp')
-rw-r--r--src/tools/moc/generator.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 1ed7de228a..9ad4d1bb68 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -954,6 +954,35 @@ void Generator::generateStaticMetacall()
}
fprintf(out, " default: ;\n");
fprintf(out, " }\n");
+
+ fprintf(out, " } else if (_c == QMetaObject::IndexOfMethod) {\n");
+ fprintf(out, " int *result = reinterpret_cast<int *>(_a[0]);\n");
+ fprintf(out, " void **func = reinterpret_cast<void **>(_a[1]);\n");
+ bool anythingUsed = false;
+ for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) {
+ const FunctionDef &f = methodList.at(methodindex);
+ if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic)
+ continue;
+ anythingUsed = true;
+ fprintf(out, " {\n");
+ fprintf(out, " typedef %s (%s::*_t)(",f.type.rawName.constData() , cdef->classname.constData());
+ for (int j = 0; j < f.arguments.count(); ++j) {
+ const ArgumentDef &a = f.arguments.at(j);
+ if (j)
+ fprintf(out, ", ");
+ fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
+ }
+ if (f.isConst)
+ fprintf(out, ") const;\n");
+ else
+ fprintf(out, ");\n");
+ fprintf(out, " if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&%s::%s)) {\n",
+ cdef->classname.constData(), f.name.constData());
+ fprintf(out, " *result = %d;\n", methodindex);
+ fprintf(out, " }\n }\n");
+ }
+ if (!anythingUsed)
+ fprintf(out, " Q_UNUSED(result);\n Q_UNUSED(func);\n");
fprintf(out, " }");
needElse = true;
}