Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. [PySide6]super().__init__() only calls first parent's __init__ if a class inherits QMainWindow and has multiple inheritance

[PySide6]super().__init__() only calls first parent's __init__ if a class inherits QMainWindow and has multiple inheritance

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 406 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yinkaisheng
    wrote on 6 Jul 2021, 07:58 last edited by yinkaisheng 7 Jul 2021, 07:21
    #1

    class_test.py

    import os
    import sys
    from PySide6.QtWidgets import QApplication, QMainWindow
    
    
    class First:
        def __init__(self):
            print('First init')
            super().__init__()
    
        def __del__(self):
            print('First del')
    
    
    class Second():
        def __init__(self):
            print('Second init')
            super().__init__()
            self.second = 2
    
        def __del__(self):
            print('Second del')
    
    
    class Third(QMainWindow, Second):
        def __init__(self):
            print('Third init')
            super().__init__()
            print(f'senond={self.second}')  # error in PySide6, self.second, object has no attribute 'second'
    
        def __del__(self):
            print('Third del')
    
    
    def main():
        app = QApplication(sys.argv)
        ob = Third()
    
    
    if __name__ == '__main__':
        main()
    
    

    The result:
    d:\Codes\Python\automation>class_test.py
    Third init
    Traceback (most recent call last):
    File "D:\Codes\Python\automation\class_test.py", line 41, in <module>
    main()
    File "D:\Codes\Python\automation\class_test.py", line 37, in main
    ob = Third()
    File "D:\Codes\Python\automation\class_test.py", line 29, in init
    print(f'senond={self.second}')
    AttributeError: 'Third' object has no attribute 'second'
    Third del

    If I change PySide6 to PyQt5, or set 'class Third(First, Second)', the scirpt runs without any error.
    Is it an error in PySide6?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Jul 2021, 16:59 last edited by
      #2

      Hi,

      Did you check PySide2 as well ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply 7 Jul 2021, 07:38
      0
      • S SGaist
        6 Jul 2021, 16:59

        Hi,

        Did you check PySide2 as well ?

        Y Offline
        Y Offline
        yinkaisheng
        wrote on 7 Jul 2021, 07:38 last edited by
        #3

        @SGaist I don't have PySide2 installed.
        My app runs well when I use PyQt5, but when I tried my app with PySide6, I met the error.
        I need to write

        class Third(QMainWindow, Second):
            def __init__(self):
                print('Third init')
                #super().__init__()
                QMainWindow.__init__(self)
                Second.__init__(self)
        

        I must refer to the base classes name explicitly in PySide6.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 Jul 2021, 17:00 last edited by
          #4

          If not already existing, you should open a ticket on the bug tracker about that matter.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          2/4

          6 Jul 2021, 16:59

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved