PyQt: RuntimeError: wrapped C/C++ object has been deleted

后端 未结 4 1732
醉酒成梦
醉酒成梦 2020-12-01 18:25

If I run this code:

    #!/usr/local/bin/    python3

import sys 
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class Window(QMainWindow):

    def          


        
4条回答
  •  孤城傲影
    2020-12-01 18:39

    Brain's answer explains the problem perfectly. This Link explain things in more detail.

    My solution to this problem was to set the widgets as attributes of the object (e.g. simply using self.label = ... instead of label = ... in your class methods). You might want to do the same for any layouts attached to the widget.

    This way you create a copy of the widget so that when C++ memory cleanup occurs, you still have a reference to the widget.

    Hope this helps.

提交回复
热议问题