qt实现登录
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
// 去掉头部
this->setWindowFlag(Qt::FramelessWindowHint);
// 去掉空白部分
this->setAttribute(Qt::WA_TranslucentBackground);
ui->lineEdit_2->setClearButtonEnabled(true);
};
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
QMessageBox box;
//设置文本框的大小
if(ui->lineEdit->text() == "admin") {
if( ui->lineEdit_2->text() == "123456" ){
int ret = QMessageBox::information(this,"提示","登录成功",QMessageBox::Ok| QMessageBox::No);
if(ret == QMessageBox::Ok){
//登录界面关闭跳转下一个界面
emit my_jump_login();
}
}else{
QMessageBox::information(this,"提示","登录失败",QMessageBox::Ok);
}
}else{
QMessageBox::information(this,"提示","登录失败",QMessageBox::Ok);
}
}
void Widget::on_pushButton_2_clicked()
{
this->close();
}
void Widget::on_pushButton_3_clicked()
{
this->showMinimized();
}
使用定时器事件 实现闹钟
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
id = startTimer(1000);
}
//重写定时器事件函数的实现
void Widget::timerEvent(QTimerEvent *e){
if(e->timerId() == id){
QTime sys = QTime::currentTime();
QString time = sys.toString("hh:mm:ss");
ui->sys_time->setText(time);
}
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_start_btn_clicked()
{
qDebug() << ui->alarm_time->text();
speecher = new QTextToSpeech(this);
if( ui->sys_time->text() == ui->voice_label->text() ){
speecher->say(ui->voice_label->text());
}
qDebug() << "label" << ui->voice_label->text();
qDebug() << ">sys_time->text:" << ui->sys_time->text();
}