#include "qqwidgets.h"
#include "ui_qqwidgets.h"
qqWidgets::qqWidgets(QWidget *parent)
: QWidget(parent)
, ui(new Ui::qqWidgets)
{
ui->setupUi(this);
// 窗口设置
this->setWindowTitle("QQ聊天");
this->setWindowIcon(QIcon(":/picture/qq.png"));
this->setFixedSize(800,600);
// logo标签
ui->logoLabel->setPixmap(QPixmap(":/picture/logo.png"));
ui->logoLabel->setScaledContents(true);
// 登陆账户标签
ui->usernameLab->resize(40,40);
ui->usernameLab->setPixmap(QPixmap(":/picture/1.png"));
ui->logoLabel->setScaledContents(true);
// 密码标签
ui->passwdLab->resize(40,40);
ui->passwdLab->setPixmap(QPixmap(":/picture/2.png"));
ui->passwdLab->setScaledContents(true);
// 登录账户输入框
ui->usernameEdit->setPlaceholderText("QQ号码/手机/邮箱");
// 密码输入框
ui->passwdEdit->setPlaceholderText("密码");
ui->passwdEdit->setEchoMode(QLineEdit::Password);
// 取消按钮 --手动连接 基于qt4版本
connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(cancelButton_clicked()));
// 登录按钮 --手动连接 基于qt5版本
connect(ui->loginButton,&QPushButton::clicked,this,&qqWidgets::loginButton_clicked);
}
qqWidgets::~qqWidgets()
{
delete ui;
}
void qqWidgets::loginButton_clicked() // 自定义的槽函数 --对应登录按钮的clicked信号
{
if(ui->usernameEdit->text() == QString::fromStdString("admin")&&ui->passwdEdit->text() == QString::fromStdString("123456"))
{
QMessageBox::information(this, "提示", "登录成功");
emit jump();
this->close();
}
else
{
int res = QMessageBox::critical(this, "错误", "账号和密码不匹配,是否重新登录",QMessageBox::Yes|QMessageBox::No);
if(res == QMessageBox::Yes)
{
ui->passwdEdit->clear(); // 系统槽函数 --清空行编辑器的内容
}
else
{
this->close();
}
}
}
void qqWidgets::cancelButton_clicked() // 自定义的槽函数 --对应取消按钮的clicked信号
{
int res = QMessageBox::question(this, "问题", "您是否确定要退出登录");
if(res == QMessageBox::Yes)
{
this->close();
}
else
{
this->close();
this->loginButton_clicked();
}
}
主函数
#include "qqwidgets.h"
#include "second.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qqWidgets w;
w.show();
Second s;
QObject::connect(&w, &qqWidgets::jump, &s, &Second::widgetjump);
return a.exec();
}