diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2020-06-15 18:01:40 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2020-06-16 12:27:02 +0000 |
commit | d0024eaf8341d041d7de1a8e8da75fdd2fd92ad4 (patch) | |
tree | f5f5b01678554636def76db4ce2a798502357f72 /examples/collidingmice | |
parent | 0e565ceb0f6142b04411944fbadbaf2b2acd2bb2 (diff) | |
download | qbs-d0024eaf8341d041d7de1a8e8da75fdd2fd92ad4.tar.gz |
Fix Qt 5.15 deprecation warnings
Change-Id: I1d6968de823c43e42ca53eb68972ba5e69dc29ed
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'examples/collidingmice')
-rw-r--r-- | examples/collidingmice/main.cpp | 1 | ||||
-rw-r--r-- | examples/collidingmice/mouse.cpp | 14 | ||||
-rw-r--r-- | examples/collidingmice/mouse.h | 2 |
3 files changed, 9 insertions, 8 deletions
diff --git a/examples/collidingmice/main.cpp b/examples/collidingmice/main.cpp index ffddf4c81..2d0514427 100644 --- a/examples/collidingmice/main.cpp +++ b/examples/collidingmice/main.cpp @@ -64,7 +64,6 @@ static const int MouseCount = 7; int main(int argc, char **argv) { QApplication app(argc, argv); - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); //! [0] //! [1] diff --git a/examples/collidingmice/mouse.cpp b/examples/collidingmice/mouse.cpp index 7075ada38..bbc718649 100644 --- a/examples/collidingmice/mouse.cpp +++ b/examples/collidingmice/mouse.cpp @@ -71,9 +71,9 @@ static qreal normalizeAngle(qreal angle) //! [0] Mouse::Mouse() : angle(0), speed(0), mouseEyeDirection(0), - color(qrand() % 256, qrand() % 256, qrand() % 256) + color(m_rand.generate() % 256, m_rand.generate() % 256, m_rand.generate() % 256) { - setRotation(qrand() % (360 * 16)); + setRotation(m_rand.generate() % (360 * 16)); } //! [0] @@ -189,16 +189,16 @@ void Mouse::advance(int step) // Add some random movement //! [10] - if (dangerMice.size() > 1 && (qrand() % 10) == 0) { - if (qrand() % 1) - angle += (qrand() % 100) / 500.0; + if (dangerMice.size() > 1 && (m_rand.generate() % 10) == 0) { + if (m_rand.generate() % 1) + angle += (m_rand.generate() % 100) / 500.0; else - angle -= (qrand() % 100) / 500.0; + angle -= (m_rand.generate() % 100) / 500.0; } //! [10] //! [11] - speed += (-50 + qrand() % 100) / 100.0; + speed += (-50 + m_rand.generate() % 100) / 100.0; qreal dx = ::sin(angle) * 10; mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5; diff --git a/examples/collidingmice/mouse.h b/examples/collidingmice/mouse.h index a98618ea5..23b9faad5 100644 --- a/examples/collidingmice/mouse.h +++ b/examples/collidingmice/mouse.h @@ -52,6 +52,7 @@ #define MOUSE_H #include <QGraphicsItem> +#include <QRandomGenerator> //! [0] class Mouse : public QGraphicsItem @@ -68,6 +69,7 @@ protected: void advance(int step) override; private: + QRandomGenerator m_rand = QRandomGenerator::securelySeeded(); qreal angle; qreal speed; qreal mouseEyeDirection; |