当前位置:网站首页>[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边栏推荐
- What if the computer folder cannot be renamed?
- Redis of non relational database [jedis client +jedis connection cluster]
- In the task manager, the CPU speed displayed is greater than its maximum speed [main frequency]
- js卡片层叠样式的图片切换js特效
- 非关系型数据库之Redis【Jedis客户端+Jedis连接集群】
- Understanding of spark operator aggregatebykey
- 2022/7/27 examination summary
- CarSim simulation quick start (XIII) - steering system
- Change the dataDir path after mysql8.0.16 installation
- Plantuml Usage Summary
猜你喜欢

Use ffmpeg to generate single image + single audio streaming video in batches

一键开关机电路

Rk3568 development board installation system startup

Meituan Er Mian: why does redis have sentinels?

OSPF comprehensive experiment (7.12)

Protobuf basic grammar summary

【13】 Adder: how to build a circuit like Lego (Part 1)?

Understanding of spark operator aggregatebykey
C language explanation series - array explanation, one-dimensional array, two-dimensional array

Some experience of gd32 using Hal Library of ST and Gd official library
随机推荐
@Documented 的作用
protobuf 基本语法总结
03 | 项目部署:如何快速部署一个基于laravel框架开发的网站
金属质感登录框样式
深度学习基础宝典---激活函数、Batch Size、归一化
Will ordinary browsers disclose information? How to protect privacy by using a secure browser?
Record a MYCAT connection and solve the problems of communications link failure
Talk about row storage and column storage of database
Swm32 series tutorial 5-adc application
Change the dataDir path after mysql8.0.16 installation
OSPF comprehensive experiment (7.12)
js信息提示框定时关闭
基于单例模式的yaml参数配置
What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
Lecture notes a utility for everyone to generate PCG
DCL singleton mode
Understanding of spark operator aggregatebykey
Can the variable modified by final be modified
Chairman tree review
我们如何在mysql中运行批处理模式?