Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QMetaMethod: Add QMetaMethod::from(&MyClass:myFunction) support #75

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions src/corelib/kernel/qmetaobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,48 @@ class Q_CORE_EXPORT QMetaMethod
template <typename PointerToMemberFunction>
static inline QMetaMethod fromSignal(PointerToMemberFunction signal)
{
typedef QtPrivate::FunctionPointer<PointerToMemberFunction> SignalType;
static_assert(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
"No Q_OBJECT in the class with the signal");
return fromSignalImpl(&SignalType::Object::staticMetaObject,
reinterpret_cast<void **>(&signal));
QMetaMethod method = from(signal);
if (method.methodType() == Signal)
{
return method;
}
return QMetaMethod();
}

template <typename PointerToMemberFunction>
static inline QMetaMethod fromSlot(PointerToMemberFunction slot)
{
QMetaMethod method = from(slot);
if (method.methodType() == Slot)
{
return method;
}
return QMetaMethod();
}

template <typename PointerToMemberFunction>
static inline QMetaMethod fromInvokable(PointerToMemberFunction invokable)
{
QMetaMethod method = from(invokable);
if (method.methodType() == Method)
{
return method;
}
return QMetaMethod();
}

template <typename PointerToMemberFunction>
static inline QMetaMethod from(PointerToMemberFunction func)
{
typedef QtPrivate::FunctionPointer<PointerToMemberFunction> ClassType;
static_assert(QtPrivate::HasQ_OBJECT_Macro<typename ClassType::Object>::Value,
"No Q_OBJECT in the class with the func");
return fromSignalImpl(&ClassType::Object::staticMetaObject,
reinterpret_cast<void **>(&func));
}

private:
// ### Qt 7: rename fromSignalImpl to fromImpl
static QMetaMethod fromSignalImpl(const QMetaObject *, void **);
static QMetaMethod fromRelativeMethodIndex(const QMetaObject *mobj, int index);
static QMetaMethod fromRelativeConstructorIndex(const QMetaObject *mobj, int index);
Expand Down
34 changes: 19 additions & 15 deletions src/tools/moc/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,30 +1157,34 @@ void Generator::generateStaticMetacall()
}

}
if (!cdef->signalList.isEmpty()) {
Q_ASSERT(needElse); // if there is signal, there was method.
if (!methodList.isEmpty()) {
Q_ASSERT(needElse); // there was method.
fprintf(out, " else if (_c == QMetaObject::IndexOfMethod) {\n");
fprintf(out, " int *result = reinterpret_cast<int *>(_a[0]);\n");
bool anythingUsed = false;
for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) {
const FunctionDef &f = cdef->signalList.at(methodindex);
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, " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData());

int argsCount = f.arguments.count();
for (int j = 0; j < argsCount; ++j) {
const ArgumentDef &a = f.arguments.at(j);
if (j)
fprintf(out, ", ");
fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
}
if (f.isPrivateSignal) {
if (argsCount > 0)
fprintf(out, ", ");
fprintf(out, "%s", "QPrivateSignal");
if (f.isRawSlot) {
fprintf(out, "QMethodRawArguments");
} else {
int argsCount = f.arguments.count();
for (int j = 0; j < argsCount; ++j) {
const ArgumentDef &a = f.arguments.at(j);
if (j)
fprintf(out, ", ");
fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
}
if (f.isPrivateSignal) {
if (argsCount > 0)
fprintf(out, ", ");
fprintf(out, "%s", "QPrivateSignal");
}
}
if (f.isConst)
fprintf(out, ") const;\n");
Expand Down