Menu

Signals inherited from a base class are not initialised

Help
2017-03-26
2017-03-26
  • David Brooks

    David Brooks - 2017-03-26

    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:

    from PythonQt import QtCore
    
    class Base(QtCore.QObject):
        sig = QtCore.Signal()
    
    b = Base()
    repr(b.sig)       # '<qt signal sig of Base instance at ...>'
    b.sig.emit()      # 
    
    class C(Base):
        pass
    
    c = C()
    repr(c.sig)       # 'Signal'
    c.sig.emit()      # Segmentation fault...
    

    Thanks,
    Dave

     
  • Florian Link

    Florian Link - 2017-03-26

    Thanks for reporting, I will have a look tomorrow.

     
  • Florian Link

    Florian Link - 2017-03-27

    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.

     
  • David Brooks

    David Brooks - 2017-03-28

    Thanks Florian for confirming the issue.

    I had a look at what appeared to be the relevant areas of code (in PythonQtInstanceWrapper_getattro() and PythonQtPrivate::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

     
  • Florian Link

    Florian Link - 2017-03-28

    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...

     
  • David Brooks

    David Brooks - 2017-03-28

    Thanks -- I'll have a look at this my tomorrow.

     
  • David Brooks

    David Brooks - 2017-03-31

    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

     
  • Florian Link

    Florian Link - 2017-03-31

    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.

     
  • Florian Link

    Florian Link - 2017-04-18

    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.

     
  • David Brooks

    David Brooks - 2017-05-23

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.