diff --git a/kdevplatform/language/duchain/duchain.cpp b/kdevplatform/language/duchain/duchain.cpp index 52bea866361b87f3035643ba0dad34eb0129835f..243efd5c07cf4ea25cac953bd6e4096ed29726e8 100644 --- a/kdevplatform/language/duchain/duchain.cpp +++ b/kdevplatform/language/duchain/duchain.cpp @@ -30,6 +30,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif #include #include @@ -1064,7 +1067,11 @@ unloadContexts: checkContextsCount = percentageOfContexts; if (visitor.checkContexts.size() > ( int )checkContextsCount) +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + startPos = QRandomGenerator::global()->bounded(visitor.checkContexts.size() - checkContextsCount); +#else startPos = qrand() % (visitor.checkContexts.size() - checkContextsCount); +#endif int endPos = startPos + maxFinalCleanupCheckContexts; if (endPos > visitor.checkContexts.size()) diff --git a/kdevplatform/shell/sessioncontroller.cpp b/kdevplatform/shell/sessioncontroller.cpp index d3e7ef5f981b18990dbd57c0111dffdecff3514a..9384262ca820a537efd3f0d219cec52d5c031cb6 100644 --- a/kdevplatform/shell/sessioncontroller.cpp +++ b/kdevplatform/shell/sessioncontroller.cpp @@ -123,7 +123,9 @@ public: void newSession() { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentDateTimeUtc().toTime_t()); +#endif Session* session = new Session( QUuid::createUuid().toString() ); KProcess::startDetached(ShellExtension::getInstance()->executableFilePath(), QStringList() << QStringLiteral("-s") << session->id().toString() << standardArguments()); @@ -415,7 +417,9 @@ Session* SessionController::createSession( const QString& name ) if(name.startsWith(QLatin1Char('{'))) { s = new Session( QUuid(name).toString(), this ); }else{ +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentDateTimeUtc().toTime_t()); +#endif s = new Session( QUuid::createUuid().toString(), this ); s->setName( name ); } @@ -502,7 +506,9 @@ QString SessionController::cloneSession( const QString& nameOrid ) Q_D(SessionController); Session* origSession = session( nameOrid ); +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentDateTimeUtc().toTime_t()); +#endif QUuid id = QUuid::createUuid(); auto copyJob = KIO::copy(QUrl::fromLocalFile(sessionDirectory(origSession->id().toString())), QUrl::fromLocalFile(sessionDirectory( id.toString()))); @@ -665,7 +671,9 @@ QString SessionController::showSessionChooserDialog(const QString& headerText, b const QString selectedSessionId = selected.sibling(selected.row(), 0).data().toString(); if (selectedSessionId.isEmpty()) { // "Create New Session" item selected, return a fresh UUID +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentDateTimeUtc().toTime_t()); +#endif return QUuid::createUuid().toString(); } return selectedSessionId; diff --git a/kdevplatform/shell/workingsetcontroller.cpp b/kdevplatform/shell/workingsetcontroller.cpp index 22a347e0a9a7fafc1a2666c9e1be95f89d3998f6..41d588bef45414c294c369159699578bd92a4c88 100644 --- a/kdevplatform/shell/workingsetcontroller.cpp +++ b/kdevplatform/shell/workingsetcontroller.cpp @@ -20,6 +20,9 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif #include "mainwindow.h" #include "partdocument.h" @@ -105,8 +108,16 @@ const QString WorkingSetController::makeSetId(const QString& prefix) const { QString newId; const uint maxRetries = 10; +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + auto* randomGenerator = QRandomGenerator::global(); +#endif for(uint retry = 2; retry <= maxRetries; retry++) { - newId = QStringLiteral("%1_%2").arg(prefix).arg(qrand() % 10000000); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + const auto random = randomGenerator->bounded(10000000); +#else + const auto random = qrand() % 10000000; +#endif + newId = QStringLiteral("%1_%2").arg(prefix).arg(random); WorkingSetIconParameters params(newId); for (WorkingSet* set : m_workingSets) { if(set->isEmpty()) { diff --git a/kdevplatform/util/tests/test_foregroundlock.cpp b/kdevplatform/util/tests/test_foregroundlock.cpp index 8e45cf8fa4a5b9c1888578eb0e4ead3031639f42..d13a35463c46f45f8516cfd34f40544968ffe1a2 100644 --- a/kdevplatform/util/tests/test_foregroundlock.cpp +++ b/kdevplatform/util/tests/test_foregroundlock.cpp @@ -21,6 +21,9 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif #include "../foregroundlock.h" @@ -38,11 +41,18 @@ public: void run() override { ForegroundLock lock(false); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + auto* randomGenerator = QRandomGenerator::global(); +#endif for (int i = 0; i < 1000; ++i) { if (lock.tryLock()) { lock.unlock(); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + QThread::usleep(randomGenerator->bounded(20)); +#else QThread::usleep(qrand() % 20); +#endif } } }; diff --git a/plugins/genericprojectmanager/tests/test_projectload.cpp b/plugins/genericprojectmanager/tests/test_projectload.cpp index bf11acaad822e9cbb87ca3c78f7158c6c95cc71f..448df864ffcdebb4f6ba100749d57502ac8bd11d 100644 --- a/plugins/genericprojectmanager/tests/test_projectload.cpp +++ b/plugins/genericprojectmanager/tests/test_projectload.cpp @@ -24,6 +24,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif #include #include @@ -99,10 +102,16 @@ bool createFile(const QString& path) return false; } - f.write(QByteArray::number(qrand())); - f.write(QByteArray::number(qrand())); - f.write(QByteArray::number(qrand())); - f.write(QByteArray::number(qrand())); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + auto* randomGenerator = QRandomGenerator::global(); +#endif + for (int i = 0; i < 4; ++i) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + f.write(QByteArray::number(randomGenerator->generate())); +#else + f.write(QByteArray::number(qrand())); +#endif + } if (!f.flush()) { qWarning() << f.errorString() << path; @@ -116,8 +125,13 @@ bool createFile(const QString& path) bool writeRandomStructure(QString path, int files) { QDir p(path); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + const QString name = QString::number(QRandomGenerator::global()->generate()); + if (QRandomGenerator::global()->bounded(5) < 1) { +#else QString name = QString::number(qrand()); if (qrand() < RAND_MAX / 5) { +#endif if (!p.mkdir(name)) { return false; } diff --git a/plugins/qmljs/duchain/tests/test_qmljscontexts.cpp b/plugins/qmljs/duchain/tests/test_qmljscontexts.cpp index 3eb2cad1df3c26922e3df4fd2718c1b748e4fc6a..4af310e50c7d437c98d40d5448a8a715310ccd51 100644 --- a/plugins/qmljs/duchain/tests/test_qmljscontexts.cpp +++ b/plugins/qmljs/duchain/tests/test_qmljscontexts.cpp @@ -30,6 +30,9 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif QTEST_GUILESS_MAIN(TestContexts) @@ -54,7 +57,12 @@ void TestContexts::testFunctionContext() QFETCH(RangeInRevision, argCtxRange); QFETCH(RangeInRevision, bodyCtxRange); - const IndexedString file(QUrl(QStringLiteral("file:///internal/%1-functionContext.js").arg(qrand()))); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + const auto random = QRandomGenerator::global()->generate(); +#else + const auto random = qrand(); +#endif + const IndexedString file(QUrl(QStringLiteral("file:///internal/%1-functionContext.js").arg(random))); ParseSession session(file, code, 0); QVERIFY(session.ast()); QCOMPARE(session.language().dialect(), QmlJS::Dialect::JavaScript);