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()