<!doctype html>LCD Number使用
LCD Number使用
随机数
rand产生随机数//产生随机数要设置种子如果不设置种子产生的随机数会重复srand设置种子
qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); //以0时0分0秒到现在的秒数为种子
srand((unsigned)time(NULL));//利用c++的方式设置随机数;
qrand()%100 //产生一个0-99的随机数,并返回
lcd显示
设置LCD Number显示 ui->lcdNumber->display();//参数QString
文本框追加:
ui->textEdit->append("要追加的字符");
猜数字源码
xxxxxxxxxx
1
2
3
4
5
MainWindow::MainWindow(QWidget *parent) :
6
QMainWindow(parent),
7
ui(new Ui::MainWindow)
8
{
9
ui->setupUi(this);
10
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
11
inum = qrand()%2;
12
connect(ui->btn0,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
13
connect(ui->btn1,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
14
connect(ui->btn2,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
15
connect(ui->btn3,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
16
connect(ui->btn4,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
17
connect(ui->btn5,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
18
connect(ui->btn6,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
19
connect(ui->btn7,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
20
connect(ui->btn8,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
21
connect(ui->btn9,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
22
connect(ui->btn_in,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
23
connect(ui->btn_out,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
24
}
25
26
MainWindow::~MainWindow()
27
{
28
delete ui;
29
}
30
void MainWindow::doProcessClinknum (){
31
QPushButton * one =(QPushButton *)sender();
32
if(one->text()=="确认"){
33
bool ok=0;
34
if(inum==num.toInt(&ok)&&ok)
35
{
36
ui->textEdit->append("输入正确");
37
}else if(inum<num.toInt(&ok)&&ok){
38
ui->textEdit->append("输入过大");
39
}else if(inum>num.toInt(&ok)&&ok){
40
ui->textEdit->append("输入过小");
41
}else{
42
ui->textEdit->append("错误");
43
}
44
//qDebug()<<inum<<endl;
45
num="0";
46
}else if(one->text()=="取消"){
47
this->close();
48
}else{
49
num=num+one->text();
50
}
51
ui->lcdNumber->display(num);
52
// qDebug()<<name<<endl;
53
qDebug()<<num<<endl;
54
}