当前位置:网站首页>[Qt5] small software with 5 people randomly selected from the bid evaluation expert base
[Qt5] small software with 5 people randomly selected from the bid evaluation expert base
2022-07-28 08:29:00 【qilei2010】
1. Software screenshot



It is also applicable to other places where something needs to be randomly selected , For example, choose students randomly 、 Lucky draw or something .
After the release of exe File and source code download address : Bid evaluation experts select small software .zip- E-government document resources -CSDN download
among myexe Folders can be copied to arbitrarily PC On , Double click on SelectName.exe You can use the software , The entered personnel name will be saved to the current folder people.txt in .
2. Design and implementation
development environment :Windows 10, Qt 5.14.2.
Programming to realize : There is no difficulty , Namely QList Random elements inside are a little difficult , I refer to This article Code for .
2.1 Screenshot of project structure

2.2 Main code
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->txtName = "people.txt";
// Create a file to save people's names
QFile file(this->txtName);
if(!file.exists())
{
file.open(QIODevice::WriteOnly);
file.close();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
// Out of order arrangement of array elements
QList<QString> MainWindow::LuanXu(QList<QString> list)
{
int length = list.size();
for(int i=0;i<length;i++)
{
QTime t = QTime::currentTime();
qsrand(t.msec()+t.second()*1000);
int r = i+qrand()%(length-i);
QString temp=list[i];
list[i]=list[r];
list[r]=temp;
}
return list;
}
// Click on label
void MainWindow::on_tabWidget_tabBarClicked(int index)
{
QFile file(this->txtName);
// Show all people
if(index == 1){
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
ui->textBrowser->setText(in.readAll());
file.close();
}
}
// Entry personnel Save button
void MainWindow::on_pushButton_2_clicked()
{
QString pname = ui->nameInput->text();
QFile file(this->txtName);
// Read people.txt, If not, create
if(!file.exists())
{
file.open(QIODevice::WriteOnly);
file.close();
}else{
// File exists
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
QTextStream stream(&file);
stream<<pname<<"\n";
file.close();
QMessageBox::information(NULL, " Tips ", " Saved successfully ");
ui->nameInput->clear();
this->on_tabWidget_tabBarClicked(1); // Refresh the display of all personnel
}
}
// Random selection of personnel
void MainWindow::on_pushButton_clicked()
{
// Read the file
QFile file(this->txtName);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QList<QString> oraList;
QTextStream in(&file);
QString line = in.readLine();
while (!line.isNull())
{
oraList.append(line);
line = in.readLine();
}
file.close();
if(oraList.size()<9){
QMessageBox::information(NULL, " Tips ", " understaffed 9 name , Please enter the person first ");
}else{
// Random selection
QList<QString> list = LuanXu(oraList);
QString rstName = list[0]+" "+list[1]+" "+list[2]+" "+list[3]+" "+list[4];
QString secName = list[5]+" "+list[6]+" "+list[7]+" "+list[8];
ui->lineEdit->setText(rstName);
ui->lineEdit_2->setText(secName);
}
}
mainwindows.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QMessageBox>
#include <QFile>
#include <QList>
#include <QTime>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
QList<QString> LuanXu(QList<QString> list);
~MainWindow();
private slots:
void on_tabWidget_tabBarClicked(int index);
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QString txtName;
};
#endif // MAINWINDOW_H边栏推荐
- Opencv's practical learning of credit card recognition (4)
- Allure use
- What if the computer file cannot be deleted?
- A group of South University students rely on science and technology to go to sea, with an annual income of 1billion
- 记录一次mycat连接Communications link failure问题解决
- Awk from introduction to earth (16) discussion on the types of awk variables -- about the two types of numbers and strings
- How to understand the adjective prefix of socket: "connection oriented" and "connectionless"
- XSS knowledge points and 20 character short domain name bypass
- Opentsdb time series database
- 演讲笔记 适合所有人的实用程序生成 PCG
猜你喜欢

Plantuml Usage Summary

Meituan Er Mian: why does redis have sentinels?

Chairman tree review

Es6: template string

Spiral matrix

No super high-rise buildings | new regulations: what information does it reveal that no new buildings above 500 meters should be built?

protobuf 基本语法总结

XSS知识点和20字符短域名绕过

MPLS -- multi protocol label switching technology

“蔚来杯“2022牛客暑期多校训练营2补题记录(DGHJKL)
随机推荐
js信息提示框定时关闭
0727~ sorting out interview questions
Information system project manager must recite the core examination site (41) risk management plan
对spark算子aggregateByKey的理解
Swm32 series tutorial 5-adc application
【13】加法器:如何像搭乐高一样搭电路(上)?
Spiral matrix
[event registration] cloud native technology exchange meetup, see you in Guangzhou on August 6
03 | project deployment: how to quickly deploy a website developed based on the laravel framework
sql server时间字段排序
基于单例模式的yaml参数配置
Mechanical revolution Jiaolong P wired network card driver can't play
Mysql中有哪些不同的表格?
c语言中函数的介绍(血书20000字!!!!)
Oracle local network service
数字签名和CA证书
PMP practice once a day | don't get lost in the exam -7.13
The even number of an integer queue is placed in the front, the odd number is placed in the back, and the relative position of the even and odd numbers remains unchanged
Regular expression for mobile number verification
Deluxe H5 Tetris game source code