最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

QT實(shí)現(xiàn)年會(huì)抽獎(jiǎng)小軟件的示例代碼

 更新時(shí)間:2022年01月21日 10:24:47   作者:KevinQUI  
本文主要介紹了QT實(shí)現(xiàn)年會(huì)抽獎(jiǎng)小軟件的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、效果展示:

1、操作說(shuō)明

下拉選擇主題,點(diǎn)擊開始按鈕,開始滾動(dòng),再次點(diǎn)擊停止,顯示幸運(yùn)之星及名稱。中選人員不參與接下來(lái)的抽取,除非軟件重啟或點(diǎn)擊復(fù)位按鈕。

二、軟件代碼介紹

1、工程目錄

2、核心代碼之主類代碼部分

main.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QCoreApplication>
#include <QDesktopWidget>
#include <QTimer>
#include <QPixmap>
#include <QSize>
#include "thread.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
? ? Q_OBJECT
? ? Thread *thread;
? ? QTimer *timer;
? ? QTimer *timer2;

public:
? ? MainWindow(QWidget *parent = nullptr);
? ? ~MainWindow();

private slots:
? ? void on_startBtn_clicked();
? ? void time2out();
? ? void show_image();
? ? void on_ResetBtn_clicked();
? ? void on_selectCase_activated(const QString &arg1);

private:
? ? Ui::MainWindow *ui;
? ? void Init();
? ? void openTxtFile(QString name);
? ? void randomSelect();
? ? void clickStop();
? ? int g_val,index;
? ? bool start;
? ? QStringList strList_store0,strList;
? ? QImage *img;

? ? const QString txt_Dir = (QCoreApplication::applicationDirPath() + "/cfg/");
? ? QString pic_Dir = (QCoreApplication::applicationDirPath() + "/photo/");

};
#endif // MAINWINDOW_H

main.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFileDialog"
#include "QMessageBox"
#include <QDebug>
#include <qmath.h>
#include <QtMath>
#include <QRandomGenerator>
MainWindow::MainWindow(QWidget *parent)
? ? : QMainWindow(parent)
? ? , ui(new Ui::MainWindow)
{
? ? ui->setupUi(this);
? ? Init();
? ? thread = new Thread;
? ? timer2 = new QTimer(this);
? ? connect(timer2,SIGNAL(timeout()),this,SLOT(time2out()));
}
MainWindow::~MainWindow()
{
? ? delete ui;
}

void MainWindow::Init(){
? ? int w = QApplication::desktop()->width();
? ? int h = QApplication::desktop()->height();
? ? this->setFixedSize(w,h);
? ? this->setWindowState(Qt::WindowMaximized);
? ? this->setWindowTitle("幸運(yùn)之星");
? ? this->setObjectName("mainWindow");
? ? this->setStyleSheet("#mainWindow{border-image:url(:/background/bg.jpg);}");

? ? start = false;
? ? ui->caseName->setText("活動(dòng)之主題");
? ? ui->caseName->setStyleSheet("font-size:60px;font-weight:500;color:yellow");
? ? ui->name->setStyleSheet("font-size:60px;font-weight:500;color:yellow");
? ? ui->startBtn->setStyleSheet("background:#f0f;");
? ? ui->ResetBtn->setStyleSheet("background:#f0f;");
? ? ui->selectCase->setStyleSheet("background:#f0f;");
? ? QDir dir(txt_Dir);
? ? QStringList nameFilters;
? ? nameFilters<<"*.txt";
? ? QStringList fileList = dir.entryList(nameFilters,QDir::Files|QDir::Readable,QDir::Name);
? ? //qDebug()<<"len:"<<fileList.length();
? ? for (int i=0;i<fileList.length();i++) {
? ? ? ? QFileInfo f = fileList.at(i);
? ? ? ? //qDebug()<<"文件名:"<<f.fileName();
? ? ? ? if(f.fileName()!=nullptr)
? ? ? ? {
? ? ? ? ? ? openTxtFile(txt_Dir+f.fileName());
? ? ? ? }else{
? ? ? ? ? ? qDebug()<<"多個(gè)文件";
? ? ? ? }
? ? }
}
void MainWindow::openTxtFile(QString filename){

? ? QFile file(filename);//從文件目錄讀取json配置文件
? ? if(!file.open(QIODevice::ReadOnly))
? ? {
? ? ? ?QMessageBox::warning(this,"Error",QString::fromLocal8Bit("無(wú)法打開配置文件!"),QMessageBox::Close);
? ? ? ?return;
? ? }

? ? QList<QString> list;

? ? QString ?l ?= file.readAll();
? ? //qDebug()<<"內(nèi)容:"<<l;
? ? strList_store0 = l.split("\r\n");
? ? strList = strList_store0;

}
void MainWindow::on_startBtn_clicked()
{
? ? if(!start)
? ? {
? ? ? ? ui->startBtn->setText("停止");
? ? ? ? start = true;
? ? ? ? timer2->start(50);
? ? ? ? thread->start();

? ? }else{
? ? ? ? ui->startBtn->setText("開始");
? ? ? ? start = false;
? ? ? ? clickStop();
? ? }
}
void MainWindow::randomSelect()
{
? ? int len;
? ? len= strList.length();
? ? if(len>1)
? ? {
? ? ? ? show_image();
? ? }
}
void MainWindow::show_image()
{
? ? img=new QImage; //新建一個(gè)image對(duì)象
? ? QString path2;
? ? int len = ?strList.length();
? ? index = rand()%len;
? ? path2 = pic_Dir+strList.at(index)+".png";
? ? qDebug()<<"path2:"<<path2;
? ? img->load(path2); //將圖像資源載入對(duì)象img,注意路徑,可點(diǎn)進(jìn)圖片右鍵復(fù)制路徑

? ? ui->image->setScaledContents(true);
? ? img->scaled(ui->image->size(),Qt::KeepAspectRatio);//Qt::SmoothTransformation
? ? ui->image->setPixmap(QPixmap::fromImage(*img));
? ? //val = ?qrand()%(len);
? ? qDebug()<<"val:"<<index;

? ? ui->name->setText(strList.at(index));
? ? delete img;
}
//出結(jié)果
void MainWindow::clickStop()
{

? ? thread->terminate();
? ? timer2->stop();
? ? strList.removeAt(index);
? ? int list_Len = strList.length();
? ? if(list_Len<2)
? ? {
? ? ? ? qDebug()<<"val:"<<index;
? ? ? ? QMessageBox::warning(this,"Error",("請(qǐng)復(fù)位后再操作!"),QMessageBox::Close);
? ? }
}
//滾動(dòng)
void MainWindow::time2out(){
? ? randomSelect();
}

void MainWindow::on_ResetBtn_clicked()
{
? ? strList = strList_store0;

}

void MainWindow::on_selectCase_activated(const QString &arg1)
{
? ? ui->caseName->setText(arg1);

}

3、核心代碼之線程類代碼部分

class Thread : public QThread
{

Q_OBJECT
public:
? ?explicit Thread(QObject *parent = 0);
? ?void run();
signals:
? ?void show_image();
public slots:
};

void Thread::run()
{
? ? while(true)
? ? {
? ? ? ? emit show_image();
? ? ? ? usleep(100000);
? ? }

}

到此這篇關(guān)于QT實(shí)現(xiàn)年會(huì)抽獎(jiǎng)小軟件的示例代碼的文章就介紹到這了,更多相關(guān)QT 抽獎(jiǎng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C語(yǔ)言如何用順序棧實(shí)現(xiàn)回文序列判斷

    C語(yǔ)言如何用順序棧實(shí)現(xiàn)回文序列判斷

    這篇文章主要為大家介紹了C語(yǔ)言如何用順序棧來(lái)實(shí)現(xiàn)回文序列的判斷,文中含有詳細(xì)的代碼示例及分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2021-10-10
  • C++ map與set封裝實(shí)現(xiàn)過(guò)程講解

    C++ map與set封裝實(shí)現(xiàn)過(guò)程講解

    set set是一種關(guān)聯(lián)式容器,下面這篇文章主要給大家介紹了關(guān)于C++中map和set使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C++具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-03-03
  • C語(yǔ)言代碼實(shí)現(xiàn)點(diǎn)餐系統(tǒng)

    C語(yǔ)言代碼實(shí)現(xiàn)點(diǎn)餐系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)點(diǎn)餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • C語(yǔ)言中static的使用方法實(shí)例詳解

    C語(yǔ)言中static的使用方法實(shí)例詳解

    static一般用于修飾局部變量,全局變量,函數(shù),下面這篇文章主要給大家介紹了關(guān)于C語(yǔ)言中static用法的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • C語(yǔ)言變量和全局變量能否重名問(wèn)題

    C語(yǔ)言變量和全局變量能否重名問(wèn)題

    這篇文章主要介紹了C語(yǔ)言變量和全局變量能否重名問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • c++歸并排序詳解

    c++歸并排序詳解

    歸并排序遵循分治法的思想:將原問(wèn)題分解為幾個(gè)規(guī)模較小但類似于原問(wèn)題的子問(wèn)題,遞歸地求解這些子問(wèn)題,然后再合并這些子問(wèn)題的解來(lái)建立原問(wèn)題的解。分治模式在每層遞歸時(shí)都有三個(gè)步驟:分解、解決、合并。歸并排序完全遵循該模式。
    2017-05-05
  • 詳解如何在C/C++中測(cè)量一個(gè)函數(shù)或功能的運(yùn)行時(shí)間

    詳解如何在C/C++中測(cè)量一個(gè)函數(shù)或功能的運(yùn)行時(shí)間

    本文算是一個(gè)比較完整的關(guān)于在 C/C++ 中測(cè)量一個(gè)函數(shù)或者功能的總結(jié),最后會(huì)演示三種方法的對(duì)比,文章通過(guò)代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • VC中LINK 2001 和 LINK 2009 的錯(cuò)誤的解決方法

    VC中LINK 2001 和 LINK 2009 的錯(cuò)誤的解決方法

    最近將兩個(gè)開源C++項(xiàng)目編譯成windows版本的時(shí)候遇到很多問(wèn)題,編譯的時(shí)候總是報(bào)錯(cuò),報(bào)的最多的是無(wú)法解析的外部符號(hào)”,經(jīng)過(guò)近3天的折騰總算都通過(guò)了,這里是一些總結(jié)
    2020-10-10
  • C++?右值引用與?const?關(guān)鍵字詳解

    C++?右值引用與?const?關(guān)鍵字詳解

    C++中的const關(guān)鍵字的用法非常靈活,而使用const將大大改善程序的健壯性,const關(guān)鍵字是一種修飾符,這篇文章主要介紹了C++?右值引用與?const?關(guān)鍵字,需要的朋友可以參考下
    2022-10-10
  • VC6.0常用快捷鍵大全

    VC6.0常用快捷鍵大全

    這篇文章主要介紹了VC6.0常用快捷鍵大全,非常實(shí)用,需要的朋友可以參考下
    2014-08-08

最新評(píng)論

融水| 马关县| 巫山县| 邛崃市| 都兰县| 利津县| 株洲市| 丰顺县| 花垣县| 玉林市| 秭归县| 云梦县| 双鸭山市| 木里| 济宁市| 紫阳县| 汕头市| 翁牛特旗| 衡阳县| 大足县| 名山县| 敦煌市| 大理市| 泾源县| 安溪县| 蒲城县| 信宜市| 新龙县| 孟连| 邹城市| 沧源| 大田县| 大姚县| 庆安县| 达孜县| 江源县| 云安县| 黄陵县| 涿州市| 双牌县| 桓台县|