You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to suggest a change to the implementation of QtCompat.wrapInstance.
Issue
In the current implementation, wrapInstance only checks if the direct superclass is a QtWidgets class. Therefore if the class has a deeper inheritance hierarchy you end up getting a QObject.
In the below example, a pointer to an instance of class B will return a QObject instead of a QDialog.
classA(QtWidgets.QDialog):
passclassB(A):
pass
Implementation
I've made changes for when base is None. Here the loop will eventually find QObject if nothing more significant is found. Alternatively you could use while meta_object is not None and add an else clause to check if the loop broke but I don't think it is necessary.
def_wrapinstance(ptr, base=None):
assertisinstance(ptr, long), "Argument 'ptr' must be of type <long>"assert (baseisNone) orissubclass(base, Qt.QtCore.QObject), (
"Argument 'base' must be of type <QObject>")
ifQt.IsPyQt4orQt.IsPyQt5:
func=getattr(Qt, "_sip").wrapinstanceelifQt.IsPySide2:
func=getattr(Qt, "_shiboken2").wrapInstanceelifQt.IsPySide:
func=getattr(Qt, "_shiboken").wrapInstanceelse:
raiseAttributeError("'module' has no attribute 'wrapInstance'")
ifbaseisNone:
q_object=func(long(ptr), Qt.QtCore.QObject)
meta_object=q_object.metaObject()
whileTrue:
class_name=meta_object.className()
try:
base=getattr(Qt.QtWidgets, class_name)
exceptAttributeError:
try:
base=getattr(Qt.QtCore, class_name)
exceptAttributeError:
meta_object=meta_object.superClass()
continuebreakreturnfunc(long(ptr), base)
The text was updated successfully, but these errors were encountered:
Yes, this is fantastic. Could you transform this into a PR? That way we can get tests running and hunt down any potential issue. The idea is sound, and from a glance it looks solid.
Hi, I would like to suggest a change to the implementation of QtCompat.wrapInstance.
Issue
In the current implementation, wrapInstance only checks if the direct superclass is a QtWidgets class. Therefore if the class has a deeper inheritance hierarchy you end up getting a QObject.
In the below example, a pointer to an instance of class B will return a QObject instead of a QDialog.
Implementation
I've made changes for when
base is None
. Here the loop will eventually find QObject if nothing more significant is found. Alternatively you could usewhile meta_object is not None
and add anelse
clause to check if the loop broke but I don't think it is necessary.The text was updated successfully, but these errors were encountered: