Skip to content

Commit ac1a096

Browse files
Removed QRandomNumberGenerator for Qt versions < 5.10
1 parent 260a2dd commit ac1a096

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

demo/MainWindow.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@
6060
#include <QToolButton>
6161
#include <QToolBar>
6262
#include <QPointer>
63-
#include <QRandomGenerator>
63+
#include <QMap>
64+
#include <QElapsedTimer>
6465

6566

67+
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
68+
#include <QRandomGenerator>
69+
#endif
70+
6671
#ifdef Q_OS_WIN
6772
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
6873
#include <QAxWidget>
6974
#endif
7075
#endif
7176

72-
#include <QMap>
73-
#include <QElapsedTimer>
74-
7577
#include "DockManager.h"
7678
#include "DockWidget.h"
7779
#include "DockAreaWidget.h"
@@ -84,6 +86,21 @@
8486
#include "ImageViewer.h"
8587

8688

89+
90+
/**
91+
* Returns a random number from 0 to highest - 1
92+
*/
93+
int randomNumberBounded(int highest)
94+
{
95+
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
96+
return QRandomGenerator::global()->bounded(highest);
97+
#else
98+
qsrand(QTime::currentTime().msec());
99+
return qrand() % highest;
100+
#endif
101+
}
102+
103+
87104
/**
88105
* Function returns a features string with closable (c), movable (m) and floatable (f)
89106
* features. i.e. The following string is for a not closable but movable and floatable
@@ -328,7 +345,7 @@ struct MainWindowPrivate
328345
{
329346
static int ImageViewerCount = 0;
330347
auto w = new CImageViewer();
331-
auto ImageIndex = QRandomGenerator::global()->bounded(4);
348+
auto ImageIndex = randomNumberBounded(4);
332349
auto FileName = ":adsdemo/images/ads_logo.svg";
333350

334351
// Pick a random image from a number of images

0 commit comments

Comments
 (0)