From a0417d080c38856137e56e3267563947423dcba2 Mon Sep 17 00:00:00 2001 From: risingLee <871066422@qq.com> Date: Sat, 7 Feb 2026 01:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20InfluxDBClient=20=E7=9A=84?= =?UTF-8?q?=20=5F=5Fdel=5F=5F=20=E9=94=99=E8=AF=AF=E6=8A=91=E5=88=B6=20Dir?= =?UTF-8?q?ectComposition=20=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- influxdb_wrapper.py | 21 ++++++++++++++++++--- main.py | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/influxdb_wrapper.py b/influxdb_wrapper.py index ab9181d..6120063 100644 --- a/influxdb_wrapper.py +++ b/influxdb_wrapper.py @@ -115,17 +115,32 @@ class InfluxDBClient(QObject): @Slot() def disconnect(self): """断开连接""" + # 安全地停止定时器(可能在程序退出时已被销毁) if self._timer: - self._timer.stop() + try: + self._timer.stop() + except RuntimeError: + # QTimer 已被销毁,忽略错误 + pass + self._timer = None if self._client: - self._client.close() + try: + self._client.close() + except Exception: + # 客户端可能已被关闭,忽略错误 + pass self._client = None self._is_connected = False def __del__(self): - self.disconnect() + """析构函数:安全地清理资源""" + try: + self.disconnect() + except Exception: + # 程序退出时 Qt 对象可能已被销毁,忽略所有异常 + pass diff --git a/main.py b/main.py index 18b21df..1e8d719 100644 --- a/main.py +++ b/main.py @@ -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()