!10 use QRandomGenerator and fix some code error

From: @hou-hongxun 
Reviewed-by: @dou33 
Signed-off-by: @dou33
This commit is contained in:
openeuler-ci-bot 2024-05-07 08:12:40 +00:00 committed by Gitee
commit 58f2d7e820
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 50 additions and 3 deletions

View File

@ -0,0 +1,41 @@
From 8a2239a0376826739d4fa1066d483a531d5c407a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BE=AF=E7=BA=A2=E5=8B=8B?= <houhongxun@kylinos.cn>
Date: Mon, 6 May 2024 14:10:34 +0800
Subject: [PATCH] use QRandomGenerator, and fix code error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
---
model/dataparser.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/model/dataparser.cpp b/model/dataparser.cpp
index 3719334..a733b29 100644
--- a/model/dataparser.cpp
+++ b/model/dataparser.cpp
@@ -1,5 +1,5 @@
#include "dataparser.h"
-
+#include <QRandomGenerator>
DataParser::DataParser() {}
//处理返回的网络数据
@@ -309,10 +309,11 @@ void DataParser::hourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)
void DataParser::tmphourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)
{
QTime current_time = QTime::currentTime();
+ QRandomGenerator rnd(current_time.msecsSinceStartOfDay());
int hour = current_time.hour() + 1; //当前的小时
for (int i = 0; i < 24; i++) {
- int num_code = qrand() % (1, 60);
- int num_tmp = qrand() % (-10, 30);
+ int num_code = rnd.bounded(0, 61);
+ int num_tmp = rnd.bounded(-10, 31);
QString tmpText = QString::number(num_tmp) + "°C";
Hourly tmp_hour;
QString hour_tmp = QString::number(hour + i) + ":00";
--
2.43.0

View File

@ -1,12 +1,13 @@
Name: kylin-weather
Version: 3.1.2
Release: 3
Release: 4
Summary: Indicator that displays China weather information
License: GPL-3.0+
URL: https://gitee.com/openkylin/kylin-weather
Source0: %{name}-%{version}.tar.gz
Patch01: 0001-fix-compile-error-of-kylin-weather.patch
Patch02: 0001-fix-coredump-of-kylin-weather.patch
Patch03: 0001-use-QRandomGenerator-and-fix-code-error.patch
BuildRequires: qt5-qtbase-devel
BuildRequires: qtchooser
@ -28,8 +29,9 @@ change it.
%prep
%setup -q
%patch01 -p1
%patch02 -p1
%patch -p1 1
%patch -p1 2
%patch -p1 3
%build
mkdir build && pushd build
@ -64,6 +66,10 @@ fi
%{_datadir}/kylin-user-guide/*
%changelog
* Mon May 06 2024 houhongxun <houhongxun@kylinos.cn> - 3.1.2-4
- use QRandomGenerator to generate random numbers
- fix some code errors
* Sat Nov 25 2023 hua_yadong <huayadong@kylinos.cn> - 3.1.2-3
- add 0001-fix-coredump-of-kylin-weather.patch