Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change qrand() , Use QRandomGenerator instead in QT > 5.10.0 #63

Merged
merged 3 commits into from
Jun 30, 2020

Conversation

gakramx
Copy link
Contributor

@gakramx gakramx commented Jun 29, 2020

Sorry for Old Pull requests
I was supposed to check it well
So
When trying to build with Cmake on my system :

Qt 5.15.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.1.0) on "xcb" 
OS: Arch Linux [linux version 5.4.49-1-lts]

The error message :


/home/akr/qtcsv/sources/writer.cpp:183:63: error: ‘int qrand()’ is deprecated: use QRandomGenerator instead [-Werror=deprecated-declarations]
  183 |         QString name = nameTemplate.arg(QString::number(qrand()));
      |                  

In QT documentation :

Note: This function is deprecated. In new applications, use QRandomGenerator instead. in QT > 5.10.0

https://doc.qt.io/qt-5/qtglobal-obsolete.html#qrand

After changing qrand() it was built without any problems .

sources/writer.cpp Outdated Show resolved Hide resolved
sources/writer.cpp Outdated Show resolved Hide resolved
@gakramx
Copy link
Contributor Author

gakramx commented Jun 30, 2020

I agree QT_VERSION_CHECK more readable .

@@ -180,7 +184,11 @@ QString WriterPrivate::getTempFileName()

for (int counter = 0; counter < std::numeric_limits<int>::max(); ++counter)
{
QString name = nameTemplate.arg(QString::number(qrand()));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QString name = nameTemplate.arg(QString::number(QRandomGenerator::global()->generate()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indent on lines 188 and 190.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@iamantony iamantony merged commit ac6e1ef into iamantony:master Jun 30, 2020
@iamantony
Copy link
Owner

Thanks @gakramx for your contribution!

@gakramx
Copy link
Contributor Author

gakramx commented Jun 30, 2020

you are welcome @iamantony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants