当前位置:网站首页>[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边栏推荐
- [book club issue 13] Chapter 1 multimedia processing tools ffmpeg tools
- 单片机IO口控制12V电压通断,MOS和三极管电路
- EMC EMI磁珠的特性
- Freezing and thawing of pytoch
- What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
- 网口网络水晶头RJ45、POE接口定义线序
- See how Google uses pre training weights in target detection tasks | CVPR 2022
- 记录一次mycat连接Communications link failure问题解决
- What if the computer desktop icon has a small yellow lock?
- 【活动报名】云原生技术交流 Meetup,8 月 6 日广州见
猜你喜欢

对spark算子aggregateByKey的理解

How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)

解析树形结构 js

XSS knowledge points and 20 character short domain name bypass

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

聊一聊数据库的行存与列存

@Documented 的作用

Qt使用信号量控制线程(QSemaphore)

OSPF comprehensive experiment (7.12)

Will ordinary browsers disclose information? How to protect privacy by using a secure browser?
随机推荐
Information system project manager must recite the core examination site (41) risk management plan
Es6: template string
How do we run batch mode in MySQL?
我们如何在mysql中运行批处理模式?
业务数字化飞速奔跑,管理数字化亟待出发
Huawei Senior Engineer -- BGP routing filtering and community attributes
PostgreSQL is the world's most advanced open source relational database
Forward propagation of deep learning neural networks (1)
03 | project deployment: how to quickly deploy a website developed based on the laravel framework
【17】建立数据通路(上):指令+运算=CPU
Redis of non relational database [detailed setup of redis cluster]
jquey的基础语法
XSS知识点和20字符短域名绕过
[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial
Chairman tree review
对spark算子aggregateByKey的理解
CarSim simulation quick start (XII) - Driver Model (2)
There are two Kafka topics that need to write data intact to MySQL King through Flink. Scheme 1: write two f's
QT uses semaphores to control threads (qsemaphore)
OpenTSDB-时序数据库