//============================================
//绝对不中,彩票开奖模拟器
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QHash>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_2_clicked()
{
    //开奖原理
    //从hash中随机找某个key,如果没有,就说明开出的奖不会有人中
    //知识点4 QString
    QString t;

// qDebug()<<rand() % 10;

for(int i=0;i<1000;i++)

{
        //5 字符串直接赋值
        t = "";
        for(int j=0;j<6;j++)
        {
            //6 ascii值-->qchar字符
            t.append( QChar(1+rand()%32));

}
        t.append(QChar(1+rand()%15));

//7 hash元素访问,op重载
        if(cp[t]<=0){
            QString t2="";
            QByteArray a;
            a=t.toLatin1(); //8 QString ==> QByteArray
            for(int j=0;j<7;j++)
            {
                t2 = t2 + QString::number(a[j])+","; //9 QString::number将int-- > Qstring
            }
            ui->lineEdit->setText(t2); //10 ui元素访问
            ui->label->setText("特等奖注数:0");
        }
    }

}

void MainWindow::on_pushButton_clicked()
{

QString t;

// qDebug()<<rand() % 10;

for(int i=0;i<1000000;i++)
    {
        t = "";
        for(int j=0;j<6;j++)
        {
            t.append( QChar(1+rand()%32));

}
        t.append(QChar(1+rand()%15));

cp[t] = cp[t] + 1; //hashmap 元素值 + 1
    }

}

源码工程下载

QT学习之路(1):彩票绝对不中模拟器的更多相关文章

  1. QT学习之路--创建一个对话框

    Q_OBJECT:这是一个宏,凡是定义信号槽的类都必须声明这个宏. 函数tr()全名是QObject::tr(),被他处理过的字符串可以使用工具提取出来翻译成其他语言,也就是做国际化使用. 对于QT学 ...

  2. 转载: Qt 学习之路 2归档

    Qt 学习之路 2归档 http://www.devbean.net/2012/08/qt-study-road-2-catelog/

  3. Qt学习之路

      Qt学习之路_14(简易音乐播放器)   Qt学习之路_13(简易俄罗斯方块)   Qt学习之路_12(简易数据管理系统)   Qt学习之路_11(简易多文档编辑器)   Qt学习之路_10(Qt ...

  4. Qt 学习之路 2

    Qt 学习之路 2 | DevBean Tech World Qt 学习之路 2 Qt 学习之路 2 目录

  5. Qt 学习之路 2(76):QML 和 QtQuick 2

    Home / Qt 学习之路 2 / Qt 学习之路 2(76):QML 和 QtQuick 2 Qt 学习之路 2(76):QML 和 QtQuick 2  豆子  2013年12月18日  Qt ...

  6. Qt 学习之路 2(74):线程和 QObject

    Home / Qt 学习之路 2 / Qt 学习之路 2(74):线程和 QObject Qt 学习之路 2(74):线程和 QObject  豆子  2013年12月3日  Qt 学习之路 2  2 ...

  7. Qt 学习之路 2(73):Qt 线程相关类

    Home / Qt 学习之路 2 / Qt 学习之路 2(73):Qt 线程相关类 Qt 学习之路 2(73):Qt 线程相关类  豆子  2013年11月26日  Qt 学习之路 2  7条评论 希 ...

  8. Qt 学习之路 2(72):线程和事件循环

    Qt 学习之路 2(72):线程和事件循环 <理解不清晰,不透彻>  --  有需求的话还需要进行专题学习  豆子  2013年11月24日  Qt 学习之路 2  34条评论 前面一章我 ...

  9. Qt 学习之路 2(71):线程简介

    Qt 学习之路 2(71):线程简介 豆子 2013年11月18日 Qt 学习之路 2 30条评论 前面我们讨论了有关进程以及进程间通讯的相关问题,现在我们开始讨论线程.事实上,现代的程序中,使用线程 ...

随机推荐

  1. hadoop2.7.7 测试安装 centos7

    useradd –m hadoop –s /bin/bash passwd hadoop   增加sudo权限 chmod u+w /etc/sudoers vi /etc/sudoers root ...

  2. css 书目录相关css+html代码

    css: <style type="text/css"> #list{width:500px;position:absolute;left:50%;margin-lef ...

  3. “2017面向对象程序设计(Java)第十三周学习总结”存在问题的反馈及本周教学安排

    “2017面向对象程序设计(Java)第十三周学习总结”存在问题的反馈及本周教学安排1. 图形界面事件处理技术是Java GUI编程核心技术,要求同学们掌握其基本原理和基本编程模型:2. 本周四理论课 ...

  4. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  5. Feign 注意事项

    一.FeignClient注解 FeignClient注解被@Target(ElementType.TYPE)修饰,表示FeignClient注解的作用目标在接口上 1 2 3 4 5 @FeignC ...

  6. Choosing the Type at Runtime

    [Choosing the Type at Runtime] You cannot use a general expression as the React element type. If you ...

  7. layout_weight 全解析

    [layout_weight 全解析] 参考:http://www.cnblogs.com/net168/p/4227144.html

  8. 初探Mybaties整合分页插件PageHelper(1)

    Mybaites整合分页PageHelper插件 在数据进行分页,通过sql语句,mysql分页,table_name表名,pageNum 第几页,pageSize 每页数据条数: SELECT * ...

  9. UltraEdit窗口布局重新设置

    解决办法:工具栏中的视图-->环境-->左边小框里选择“编程员”,再点选择环境 转载:https://blog.csdn.net/u011650048/article/details/18 ...

  10. 机器人编程挑战python

    机器人编程挑战 要使用pip安装模拟器,请运行pip install zombiedice(在Windows上)或pip3 install zombiedice(在macOS和Linux上).要使用一 ...