修复 InfluxDBClient 的 __del__ 错误抑制 DirectComposition 警告

main
risingLee 2026-02-07 01:33:40 +08:00
parent 3b644a3acb
commit a0417d080c
2 changed files with 22 additions and 3 deletions

View File

@ -115,17 +115,32 @@ class InfluxDBClient(QObject):
@Slot()
def disconnect(self):
"""断开连接"""
# 安全地停止定时器(可能在程序退出时已被销毁)
if self._timer:
try:
self._timer.stop()
except RuntimeError:
# QTimer 已被销毁,忽略错误
pass
self._timer = None
if self._client:
try:
self._client.close()
except Exception:
# 客户端可能已被关闭,忽略错误
pass
self._client = None
self._is_connected = False
def __del__(self):
"""析构函数:安全地清理资源"""
try:
self.disconnect()
except Exception:
# 程序退出时 Qt 对象可能已被销毁,忽略所有异常
pass

View File

@ -1540,6 +1540,10 @@ class MainWindow(QMainWindow):
def main():
# 抑制 Windows 上 QWebEngineView 的 DirectComposition 警告
import os
os.environ.setdefault('QT_LOGGING_RULES', 'qt.webenginecontext.debug=false')
app = QApplication(sys.argv)
win = MainWindow()
win.show()