<!doctype html>LCD Number使用
rand产生随机数//产生随机数要设置种子如果不设置种子产生的随机数会重复srand设置种子
qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); //以0时0分0秒到现在的秒数为种子
qrand()%100 //产生一个0-99的随机数,并返回
设置LCD Number显示 ui->lcdNumber->display();//参数QString
ui->textEdit->append("要追加的字符");
xxxxxxxxxx
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
inum = qrand()%2;
connect(ui->btn0,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn1,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn2,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn3,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn4,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn5,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn6,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn7,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn8,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn9,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn_in,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
connect(ui->btn_out,SIGNAL(clicked(bool)),this,SLOT(doProcessClinknum()));
}
?
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::doProcessClinknum (){
QPushButton * one =(QPushButton *)sender();
if(one->text()=="确认"){
bool ok=0;
if(inum==num.toInt(&ok)&&ok)
{
ui->textEdit->append("输入正确");
}else if(inum<num.toInt(&ok)&&ok){
ui->textEdit->append("输入过大");
}else if(inum>num.toInt(&ok)&&ok){
ui->textEdit->append("输入过小");
}else{
ui->textEdit->append("错误");
}
//qDebug()<<inum<<endl;
num="0";
}else if(one->text()=="取消"){
this->close();
}else{
num=num+one->text();
}
ui->lcdNumber->display(num);
// qDebug()<<name<<endl;
qDebug()<<num<<endl;
}
原文:https://www.cnblogs.com/lxuechao/p/12580964.html