Skip to content

Commit 1e8ea80

Browse files
florianlinkmsmolens
florianlink
authored andcommitted
improved handling of qualified virtual calls
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@402 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent 63c9668 commit 1e8ea80

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/PythonQtClassWrapper.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,19 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name)
512512
Py_INCREF(enumWrapper);
513513
return enumWrapper;
514514
} else if (member._type == PythonQtMemberInfo::Slot) {
515-
// we return all slots, even the instance slots, since they are callable as unbound slots with self argument
516-
return PythonQtSlotFunction_New(member._slot, obj, NULL);
515+
// NOTE: this does an extra lookup and string copy, it might be better to move this to
516+
// PythonQtClassInfo and add a new cache for qualified class methods...
517+
QByteArray qualifiedMemberName = "py_q_";
518+
qualifiedMemberName += attributeName;
519+
PythonQtMemberInfo qualifiedMember = wrapper->classInfo()->member(qualifiedMemberName);
520+
if (qualifiedMember._type == PythonQtMemberInfo::Slot) {
521+
// return the qualified member, so that virtual calls on classes call the qualified member
522+
return PythonQtSlotFunction_New(qualifiedMember._slot, obj, NULL);
523+
}
524+
else {
525+
// we return all slots, even the instance slots, since they are callable as unbound slots with self argument
526+
return PythonQtSlotFunction_New(member._slot, obj, NULL);
527+
}
517528
} else if (member._type == PythonQtMemberInfo::Signal) {
518529
// we return all signals, even the instance signals, since they are callable as unbound signals with self argument
519530
return PythonQtSignalFunction_New(member._slot, obj, NULL);

src/PythonQtMethodInfo.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ QString PythonQtSlotInfo::fullSignature(bool skipReturnValue, int optionalArgsIn
401401
if (sig.startsWith("new_")) {
402402
sig = sig.mid(4);
403403
isConstructor = true;
404-
} else if (sig.startsWith("delete_")) {
404+
}
405+
else if (sig.startsWith("py_q_")) {
406+
sig = sig.mid(5);
407+
}
408+
else if (sig.startsWith("delete_")) {
405409
sig = sig.mid(7);
406410
isDestructor = true;
407411
} else if(sig.startsWith("static_")) {
@@ -471,6 +475,9 @@ QByteArray PythonQtSlotInfo::slotName(bool removeDecorators) const
471475
{
472476
QByteArray name = PythonQtUtils::methodName(_meta);
473477
if (removeDecorators) {
478+
if (name.startsWith("py_q_")) {
479+
name = name.mid(5);
480+
} else
474481
if (name.startsWith("static_")) {
475482
name = name.mid(7);
476483
int idx = name.indexOf("_");

0 commit comments

Comments
 (0)