setPixmap crashing when trying to show image in label

后端 未结 1 1422
悲&欢浪女
悲&欢浪女 2020-12-12 04:39

I have created a minimal example with pyqt designer, that changes the text of a label when a button is pressed and is supposed to present a screenshot in the window, via the

相关标签:
1条回答
  • 2020-12-12 05:03

    "screenshot" shares the same memory with "qimg", and as screenshot it is a local variable that when eliminated the associated memory is also eliminated so the QPbelmap of the QLabel when trying to access information will generate a Segmentation fault. The solution is to make a copy so that they do not share the same memory

    def take_screenshot(self):
        screenshot = grab()
        qim = ImageQt(screenshot).copy()
        pix = QtGui.QPixmap.fromImage(qim)
        self.label.setPixmap(pix)
        self.label.adjustSize()
    0 讨论(0)
提交回复
热议问题