Menu

Slots are not accessible via super()

Help
2017-06-02
2017-06-02
  • David Brooks

    David Brooks - 2017-06-02

    Although slots of Qt objects can be called as methods in derived classes when invoked directly, they cannot be called by using super(), as demonstrated below. What is required to implement this??

    Thanks.

    >>> from PythonQt import QtGui
    >>> 
    >>> class C(QtGui.QWidget):
    ...   pass
    ... 
    >>> c = C()
    >>> 
    >>> c.objectName
    <qt slot objectName of C instance at 0x12306dac8>
    >>> 
    >>> c.objectName()
    ''
    >>> c.setObjectName('c')
    >>> c.objectName()
    'c'
    >>> 
    >>> super(C, c).objectName()
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    AttributeError: 'super' object has no attribute 'objectName'
    >>> 
    
     
  • Florian Link

    Florian Link - 2017-06-02

    I never used super in Python, did you try

    QtCore.QObject.objectName()

    By the way, I am wondering that it is available as a slot, since properties have precedence in PythonQt and objectName is a property?

     
  • David Brooks

    David Brooks - 2017-06-02

    My question is about referencing slots using super() and not about calling objectName() -- this is just an example -- as I'm trying to run existing code that makes extensive use of super.

    Another example:

    >>> from PythonQt import QtGui
    >>> 
    >>> t = QtGui.QTextDocument()
    >>> h = QtGui.QSyntaxHighlighter(t)
    >>> 
    >>> h.currentBlock()
    QTextBlock (C++ object at: 0x7f9d04c6cd50)
    >>> 
    >>> super(QtGui.QSyntaxHighlighter, h).currentBlock()
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    AttributeError: 'super' object has no attribute 'currentBlock'
    
     
  • David Brooks

    David Brooks - 2017-06-02

    Oops, bad example... I meant:

    >>> from PythonQt import QtGui
    >>> 
    >>> t = QtGui.QTextDocument()
    >>> 
    >>> class C(QtGui.QSyntaxHighlighter):
    ...   def __init__(self, b):
    ...     super(C, self).__init__(b)
    ... 
    >>> c = C(t)
    >>> c.currentBlock()
    QTextBlock (C++ object at: 0x7f9d04d83fe0)
    >>>
    >>> super(C, c).currentBlock()
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    AttributeError: 'super' object has no attribute 'currentBlock' 
    
     
  • Florian Link

    Florian Link - 2017-06-02

    You misunderstood me, I mean if you can call a method on the super class like this:

    QtCore.QObject().setObjectName(self, "name")

    Hm, I don't know what super does/expects from the PythonQt wrappers to make this work.

     
  • David Brooks

    David Brooks - 2017-06-02

    Sure, that works, but the point of using super() is to have Python search back through the MRO without have to explicitely refer to base classes. From reading the Descriptor HowTo Guide relevant code is in Objects/typeobject.c but I'm not sure of what would need doing in PythonQt's code.

     

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.