Python PySide (Internal c++ Object Already Deleted)

后端 未结 2 1549
耶瑟儿~
耶瑟儿~ 2021-01-03 22:07

I recently decided to write my first app with Python and PySide. But I have a problem and hope you guys can help.

Python keeps raising exceptions that the \"Internal

相关标签:
2条回答
  • 2021-01-03 22:37

    After some searching and hair pulling, I found the solution. I was showing all the pages by setting them as the central widget, and when reading the QMainWindow documentation I found that my widget basically gets deleted by qt as stated:

    Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

    So to develop a Multi-Page application rather take a look at QStackedWidget.

    0 讨论(0)
  • 2021-01-03 22:43

    See here: PySide Pitfalls.

    If a QObject falls out of scope in Python, it will get deleted. You have to take care of keeping a reference to the object:

    • Store it as an attribute of an object you keep around, e.g. self.window = QMainWindow()
    • Pass a parent QObject to the object’s constructor, so it gets owned by the parent
    0 讨论(0)
提交回复
热议问题