diff options
| author | melvo <melvo@olomono.de> | 2020-03-29 22:15:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-29 22:15:52 +0200 |
| commit | 7f080d08252dfb699d4e3ae072cc3db0d2de129d (patch) | |
| tree | b20dfe59b2e0730ffdaeaf53f129585393802a90 | |
| parent | 13870274bba1765a1fcecedb5bcc0eda8db682eb (diff) | |
| download | qxmpp-7f080d08252dfb699d4e3ae072cc3db0d2de129d.tar.gz | |
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.
| -rw-r--r-- | src/base/QXmppStream.cpp | 4 | ||||
| -rw-r--r-- | src/base/QXmppUtils.cpp | 10 |
2 files changed, 13 insertions, 1 deletions
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 <QTime> #include <QXmlStreamWriter> +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) static bool randomSeeded = false; +#endif static const QByteArray streamRootElementEnd = QByteArrayLiteral("</stream:stream>"); 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<quintptr>(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 <QDateTime> #include <QDebug> #include <QDomElement> +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include <QRandomGenerator> +#endif #include <QRegExp> #include <QString> #include <QStringList> @@ -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; } |
