Details
Description
This tickets arose out of https://github.com/pytest-dev/pytest-qt/issues/552.
There is a number of issues new in 6.7.0 revolving around warnings when disconnecting signals.
1. This code prints warnings that cannot be suppressed in Python:
import warnings from PySide6.QtCore import Signal from PySide6.QtWidgets import QApplication, QMainWindow warnings.filterwarnings('ignore') class Window(QMainWindow): signal = Signal() def __init__(self): super().__init__() self.signal.connect(self.Slot) self.signal.disconnect(self.Slot) self.signal.disconnect(self.Slot) def Slot(self): ... warnings.warn(Warning("some warning")) app = QApplication() window = Window() print("Done")
2. This code shows that the warnings appear somewhat inconsistently. Run this code several times, and you will see the warning 1 or 2 times. If you see it only once, increase "10"; if you see it only twice, decrease "10":
from PySide6.QtCore import QTimer from PySide6.QtWidgets import QApplication class MyClass: def __init__(self): self.timer = QTimer() self.timer.timeout.disconnect(self.empty) def empty(self): ... app = QApplication() for _ in range(10): MyClass()
3. This code shows that the warnings appears depending on whether the reference to the MyClass object is stored in a variable or not:
from PySide6.QtCore import QTimer from PySide6.QtWidgets import QApplication, QWidget class MyClass: def __init__(self, signal): self.timer = QTimer() signal.connect(self.cleanup) def cleanup(self): self.timer.timeout.disconnect(self.cleanup) app = QApplication() widget = QWidget() signal = widget.windowTitleChanged print("- no warning:") MyClass(signal) signal.emit("") print("- warning:") _class = MyClass(signal) signal.emit("")
Attachments
Issue Links
- relates to
-
PYSIDE-1275 disconnecting a signal that hasn't been connected throws exception
- Closed