From 0d9714f44549bf2e3a39d5c9833a4744cc3e6410 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 20:48:56 +0100 Subject: moc: Only generate IndexOfMethod for signals. moc is currently generating code to convert from a pointer to member function of a slot or signal to its index. The idea was that it could be usefull for slots to have the new syntax do the same as the old one (connecting signal index to slot index). But in practice, the new syntax do not use the IndexOfMethod for slots. Also, it does not work for all the slots (no Q_PRIVATE_SLOT, no static slots) So since it is not used, and that it would take room in the binaries to generate all the code to get the index of slots, we remove it. If ever we need it, we can still add it later. Change-Id: Ia417e3e524d7915ca86433ea86c66ac2b299c81a Reviewed-by: Kent Hansen --- src/tools/moc/generator.cpp | 12 ++++++++---- tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index c7c7d96487..ac602fd6e8 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -951,13 +951,17 @@ void Generator::generateStaticMetacall() } fprintf(out, " default: ;\n"); fprintf(out, " }\n"); - - fprintf(out, " } else if (_c == QMetaObject::IndexOfMethod) {\n"); + fprintf(out, " }"); + needElse = true; + } + if (!cdef->signalList.isEmpty()) { + Q_ASSERT(needElse); // if there is signal, there was method. + fprintf(out, " else if (_c == QMetaObject::IndexOfMethod) {\n"); fprintf(out, " int *result = reinterpret_cast(_a[0]);\n"); fprintf(out, " void **func = reinterpret_cast(_a[1]);\n"); bool anythingUsed = false; - for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) { - const FunctionDef &f = methodList.at(methodindex); + for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) { + const FunctionDef &f = cdef->signalList.at(methodindex); if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic) continue; anythingUsed = true; diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 68ff8e4bb6..09fd0a7adb 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -326,6 +326,8 @@ public slots: signals: void sig0(); QString sig1(QString s1); + void sig10(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7, + QString s8, QString s9, QString s10); protected: QtTestObject(QVariant) {} @@ -725,6 +727,7 @@ typedef QString CustomString; class QtTestCustomObject: public QObject { Q_OBJECT + friend class tst_QMetaObject; public: QtTestCustomObject(): QObject(), sum(0) {} @@ -1129,11 +1132,9 @@ void tst_QMetaObject::indexOfMethodPMF() } INDEXOFMETHODPMF_HELPER(tst_QMetaObject, value7Changed, (const QString&)) - INDEXOFMETHODPMF_HELPER(tst_QMetaObject, stdSet, ()) - INDEXOFMETHODPMF_HELPER(QtTestObject, sl10, (QString,QString,QString,QString,QString,QString,QString,QString,QString,QString)) INDEXOFMETHODPMF_HELPER(QtTestObject, sig0, ()) - INDEXOFMETHODPMF_HELPER(QtTestObject, testLongLong, (qint64, quint64)) - INDEXOFMETHODPMF_HELPER(QtTestObject, testReference, (QString&)) + INDEXOFMETHODPMF_HELPER(QtTestObject, sig10, (QString,QString,QString,QString,QString,QString,QString,QString,QString,QString)) + INDEXOFMETHODPMF_HELPER(QtTestCustomObject, sig_custom, (const CustomString &)) } QTEST_MAIN(tst_QMetaObject) -- cgit v1.2.3