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