Signals inherited from a base class are not initialised
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi,
I'm trying to use a Signal that is defined in a base class and have found that it doesn't get initialised when used in an instance. A simple example:
Thanks,
Dave
Thanks for reporting, I will have a look tomorrow.
I can reproduce the problem... I will put it onto my TODO list to support derived Python classes, but I can't promise that I can fix this soon.
Thanks Florian for confirming the issue.
I had a look at what appeared to be the relevant areas of code (in
PythonQtInstanceWrapper_getattro()
andPythonQtPrivate::buildDynamicMetaObject()
) before raising the issue -- are you able to give some pointers as to what needs to be done (that is how to best instantiate the Signal attribute)? I'll then have a go at fixing things.Regards, Dave
Hm, I think the problem is that each derived Python class goes directly up to the PythonQt wrapper class, instead of recursively creating the QMetaObject for each Python class in the hierachy and deriving the dynamic meta objects in the correct order. I can't say much more without going into details myself...
Thanks -- I'll have a look at this my tomorrow.
The attached diff for PythonQt.cpp seems to do the job, at least for my simple test case -- I'll do some more testing over the next few days. Comments would be welcome as I've possibly overlooked something obvious...
Thanks, Dave
Yes, that looks ok, but I was more thinking along the line of deriving the QMetaObjects from each other, so that there is a QMetaObject "Base" and a QMetaObject "C" which is derived from the "Base" meta object. Your code generates a QMetaObject "C" that is not derived from "Base", but directly from QObject.
I think the trick is to call the meta object creation on each class hierachy, starting from the class abover PythonQtClassWrapper until reaching the target class in the hierarchy and always using QMetaObject from the previous class as base meta object for the next class.
I now implemented the correct support for deriving a chain of Python classes from a Qt wrapper.
Each class now gets it's own QMetaObject which is correctly derived from the super class's meta object. I commited this on the SVN trunk.
Thanks Florian for doing this. I've had to take a break from development but am now back and can confirm that this all works for me.