From 7f080d08252dfb699d4e3ae072cc3db0d2de129d Mon Sep 17 00:00:00 2001 From: melvo Date: Sun, 29 Mar 2020 22:15:52 +0200 Subject: Replace deprecated 'qsrand()' and 'qrand()' by QRandomGenerator (#267) Since QRandomGenerator is only available since Qt 5.10, the deprecated functions are still used for Qt < 5.10. --- src/base/QXmppStream.cpp | 4 ++++ src/base/QXmppUtils.cpp | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp index 1d81dbdb..dac3a02a 100644 --- a/src/base/QXmppStream.cpp +++ b/src/base/QXmppStream.cpp @@ -40,7 +40,9 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) static bool randomSeeded = false; +#endif static const QByteArray streamRootElementEnd = QByteArrayLiteral(""); class QXmppStreamPrivate @@ -74,11 +76,13 @@ QXmppStream::QXmppStream(QObject *parent) : QXmppLoggable(parent), d(new QXmppStreamPrivate) { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) // Make sure the random number generator is seeded if (!randomSeeded) { qsrand(QTime(0, 0, 0).msecsTo(QTime::currentTime()) ^ reinterpret_cast(this)); randomSeeded = true; } +#endif } /// diff --git a/src/base/QXmppUtils.cpp b/src/base/QXmppUtils.cpp index 23071580..1c0c1906 100644 --- a/src/base/QXmppUtils.cpp +++ b/src/base/QXmppUtils.cpp @@ -32,6 +32,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif #include #include #include @@ -280,8 +283,13 @@ int QXmppUtils::generateRandomInteger(int N) { Q_ASSERT(N > 0 && N <= RAND_MAX); int val; +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + while (N <= (val = QRandomGenerator::global()->generate() / (RAND_MAX / N))) { + } +#else while (N <= (val = qrand() / (RAND_MAX / N))) { - }; + } +#endif return val; } -- cgit v1.2.3