Understanding the “underlying C/C++ object has been deleted” error

前端 未结 5 1756
故里飘歌
故里飘歌 2020-12-24 14:00

It\'s not the first time I am getting the RuntimeError: underlying C/C++ object has been deleted. I\'ve solved it many times altering my code in a random but in

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 14:18

    As of Python 3+ you can simplify the code even further.

    from PyQt4.QtCore import *
    
    class SomeTableModel(QAbstractTableModel):
      def __init__(self, filename):
        super().__init__()   # No longer need to specify class name, or self
    

    Super also grants some extra safeguards mentioned here: Understanding Python super() with __init__() methods

提交回复
热议问题