Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageLabelMessageBoxBase 组合使用的时候会产生内存泄漏 #977

Closed
rainzee opened this issue Sep 27, 2024 · 1 comment
Closed

Comments

@rainzee
Copy link
Contributor

rainzee commented Sep 27, 2024

ImageLabelMessageBoxBase 组合使用的时候会产生内存泄漏,注意当使用 QDialog 时没有该问题产生

最小复现代码

import requests
from PyQt5.QtCore import QThreadPool, pyqtSignal
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QDialog, QPushButton, QVBoxLayout, QWidget
from qfluentwidgets import ImageLabel, MessageBoxBase


class ImageDialog(MessageBoxBase):
    imageDataFetched = pyqtSignal(bytes)

    def __init__(self, parent: QWidget | None = None) -> None:
        super().__init__(parent)
        # self.mainLayout = QVBoxLayout(self)
        self.posterLabel = ImageLabel(self)
        self.viewLayout.addWidget(self.posterLabel)
        self.imageDataFetched.connect(self.setImage)
        QThreadPool.globalInstance().start(self.fetchImage)

    def fetchImage(self) -> None:
        resp = requests.get("https://qfluentwidgets.com/img/features/dark-store.jpg")
        self.imageDataFetched.emit(resp.content)

    def setImage(self, imgData: bytes) -> None:
        img = QPixmap()
        img.loadFromData(imgData)
        self.posterLabel.setPixmap(img)


class View(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.resize(400, 300)
        self.mainLayout = QVBoxLayout(self)
        self.btn = QPushButton("show dialog", self)
        self.btn.clicked.connect(self.showDialog)
        self.mainLayout.addWidget(self.btn)

    def showDialog(self) -> None:
        dialog = ImageDialog(self)
        dialog.exec()


if __name__ == "__main__":
    app = QApplication([])
    view = View()
    view.show()
    app.exec()

@zhiyiYo
Copy link
Owner

zhiyiYo commented Sep 27, 2024

已修复此问题

@zhiyiYo zhiyiYo closed this as completed Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants