From d80cead0be7ef3e460fc05f16458e7075eb17733 Mon Sep 17 00:00:00 2001 From: lachlangrose Date: Tue, 4 Aug 2026 09:40:40 +0930 Subject: [PATCH] fix: update qgis4 compatibility --- loopstructural/gui/compatibility.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/loopstructural/gui/compatibility.py b/loopstructural/gui/compatibility.py index a7d6852..b74a536 100644 --- a/loopstructural/gui/compatibility.py +++ b/loopstructural/gui/compatibility.py @@ -1,7 +1,14 @@ # compat.py from qgis.PyQt.QtCore import QVariant -try: +if hasattr(QVariant, "Int"): + # QGIS 3 / PyQt5: QVariant still exposes the legacy .Type enum members. + # (QMetaType is importable under PyQt5 too, so we can't use that import + # to detect QGIS 4 - checking for the attribute QGIS 4 actually removed + # is the only reliable signal.) + QVariantCompat = QVariant +else: + # QGIS 4 / PyQt6: QVariant.Type was removed; use QMetaType instead. from qgis.PyQt.QtCore import QMetaType # We create a proxy class to mimic the old QVariant.Type behavior @@ -12,9 +19,6 @@ class QVariantProxy: Double = QMetaType.Type.Double String = QMetaType.Type.QString Bool = QMetaType.Type.Bool + DateTime = QMetaType.Type.QDateTime - # In QGIS 4, we use our proxy QVariantCompat = QVariantProxy -except (ImportError, AttributeError): - # In QGIS 3, QVariant already has .Type - QVariantCompat = QVariant