aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-11-30 12:46:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-02-16 16:07:12 +0200
commit0905bf78e2584bbdff05a15826bdaba4170579d6 (patch)
treeeab51ff64a5e87e50763ec510b4b440145adf72e
parentecaafacbe574069d749f3a006259d179028f2399 (diff)
Avoid using deprecated APIs in Qt5 and Qt6HEADmaster
Note that support for QLinkedList can be enabled with the ODB_QT_FORCE_QLINKEDLIST macro.
-rw-r--r--odb/qt/containers/qlinked-list-traits.hxx9
-rw-r--r--odb/qt/date-time/sqlite/qdate-time-traits.hxx16
-rw-r--r--odb/qt/date-time/sqlite/qdate-traits.hxx20
3 files changed, 41 insertions, 4 deletions
diff --git a/odb/qt/containers/qlinked-list-traits.hxx b/odb/qt/containers/qlinked-list-traits.hxx
index 378a472..3bfc9e9 100644
--- a/odb/qt/containers/qlinked-list-traits.hxx
+++ b/odb/qt/containers/qlinked-list-traits.hxx
@@ -6,6 +6,13 @@
#include <odb/pre.hxx>
+#include <QtCore/QtGlobal> // QT_VERSION
+
+// QLinkedList is deprecated since Qt5 5.15 and in Qt6 it has been moved to a
+// separate library.
+//
+#if (QT_VERSION < 0x050F00) || ODB_QT_FORCE_QLINKEDLIST
+
#include <QtCore/QLinkedList>
#include <odb/container-traits.hxx>
@@ -68,6 +75,8 @@ namespace odb
};
}
+#endif
+
#include <odb/post.hxx>
#endif // ODB_QT_CONTAINER_QLINKED_LIST_TRAITS_HXX
diff --git a/odb/qt/date-time/sqlite/qdate-time-traits.hxx b/odb/qt/date-time/sqlite/qdate-time-traits.hxx
index 143b0f4..db561fc 100644
--- a/odb/qt/date-time/sqlite/qdate-time-traits.hxx
+++ b/odb/qt/date-time/sqlite/qdate-time-traits.hxx
@@ -10,6 +10,8 @@
#include <cstddef> // std::size_t
#include <cstring> // std::memcpy
+#include <QtCore/QtGlobal> // QT_VERSION
+
#include <QtCore/QDateTime>
#include <odb/details/buffer.hxx>
@@ -90,7 +92,14 @@ namespace odb
else
{
v.setTimeSpec (Qt::UTC);
- v.setTime_t (static_cast <uint> (i));
+
+ // *Time_t() functions are deprecated in favor of *SecsSinceEpoch().
+ //
+#if QT_VERSION < 0x060000
+ v.setTime_t (static_cast<uint> (i));
+#else
+ v.setSecsSinceEpoch (static_cast<qint64> (i));
+#endif
}
}
@@ -106,7 +115,12 @@ namespace odb
else
{
is_null = false;
+
+#if QT_VERSION < 0x060000
i = static_cast<long long> (v.toTime_t ());
+#else
+ i = static_cast<long long> (v.toSecsSinceEpoch ());
+#endif
}
}
};
diff --git a/odb/qt/date-time/sqlite/qdate-traits.hxx b/odb/qt/date-time/sqlite/qdate-traits.hxx
index 2810d02..52721b7 100644
--- a/odb/qt/date-time/sqlite/qdate-traits.hxx
+++ b/odb/qt/date-time/sqlite/qdate-traits.hxx
@@ -10,7 +10,10 @@
#include <cstddef> // std::size_t
#include <cstring> // std::memcpy
+#include <QtCore/QtGlobal> // QT_VERSION
+
#include <QtCore/QDate>
+#include <QtCore/QDateTime>
#include <odb/details/buffer.hxx>
#include <odb/sqlite/traits.hxx>
@@ -92,8 +95,14 @@ namespace odb
{
QDateTime dt;
dt.setTimeSpec (Qt::UTC);
- dt.setTime_t (static_cast<uint> (i));
+ // *Time_t() functions are deprecated in favor of *SecsSinceEpoch().
+ //
+#if QT_VERSION < 0x060000
+ dt.setTime_t (static_cast<uint> (i));
+#else
+ dt.setSecsSinceEpoch (static_cast<qint64> (i));
+#endif
v = dt.date ();
}
}
@@ -108,8 +117,13 @@ namespace odb
else
{
is_null = false;
- i = static_cast<long long> (
- QDateTime (v, QTime (0, 0, 0), Qt::UTC).toTime_t ());
+ const QDateTime dt (v, QTime (0, 0, 0), Qt::UTC);
+
+#if QT_VERSION < 0x060000
+ i = static_cast<long long> (dt.toTime_t ());
+#else
+ i = static_cast<long long> (dt.toSecsSinceEpoch ());
+#endif
}
}
};