From ac1a0962d3c827e1235923d4e30bbb84d9b25b7d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 15 Nov 2022 14:35:52 +0100 Subject: [PATCH] Removed QRandomNumberGenerator for Qt versions < 5.10 --- demo/MainWindow.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 4404053..466bcc1 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -60,18 +60,20 @@ #include #include #include -#include +#include +#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif + #ifdef Q_OS_WIN #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif #endif -#include -#include - #include "DockManager.h" #include "DockWidget.h" #include "DockAreaWidget.h" @@ -84,6 +86,21 @@ #include "ImageViewer.h" + +/** + * Returns a random number from 0 to highest - 1 + */ +int randomNumberBounded(int highest) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + return QRandomGenerator::global()->bounded(highest); +#else + qsrand(QTime::currentTime().msec()); + return qrand() % highest; +#endif +} + + /** * Function returns a features string with closable (c), movable (m) and floatable (f) * features. i.e. The following string is for a not closable but movable and floatable @@ -328,7 +345,7 @@ struct MainWindowPrivate { static int ImageViewerCount = 0; auto w = new CImageViewer(); - auto ImageIndex = QRandomGenerator::global()->bounded(4); + auto ImageIndex = randomNumberBounded(4); auto FileName = ":adsdemo/images/ads_logo.svg"; // Pick a random image from a number of images