7.8作业

1、main.cpp

#include "widget.h"
#include "second.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    Second b;
    QObject::connect(&w,&Widget::jump,&b,&Second::jump_slot);
    return a.exec();
}

2、second.cpp

#include "second.h"
#include "ui_second.h"

Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
}

Second::~Second()
{
    delete ui;
}

void Second::jump_slot(){
    this->show();
}

3、widget.cpp

#include "widget.h"

void Widget::my_slot(){
    if(edit_usr->text()=="admin"&&edit_pd->text()=="123456"){  //账号匹配
       Widget::jump();  //登录成功,跳转
       //this->hide();
       qDebug() << "登录成功";
    }else{
       qDebug() << "登录失败";
    }
}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(600,400);
    this->setWindowIcon(QIcon(":/icon/R-C.png"));
    this->setWindowTitle("夸克聊天室");

    //logo框
    lab1=new QLabel(this);
    lab1->resize(600,180);
    lab1->setPixmap(QPixmap(":/icon/quark.jpg"));
    lab1->setScaledContents(true);

    //用户头像
    lab2=new QLabel(this);
    lab2->resize(40,40);
    lab2->move(180,200);
    lab2->setPixmap(QPixmap(":/icon/usr.png"));
    lab2->setScaledContents(true);
    //账号框
    edit_usr=new QLineEdit(this);
    edit_usr->move(230,210);
    edit_usr->setPlaceholderText("账号");


    //密码图像
    lab3=new QLabel(this);
    lab3->resize(35,35);
    lab3->move(180,250);
    lab3->setPixmap(QPixmap(":/icon/pd.png"));
    lab3->setScaledContents(true);
    //密码框
    edit_pd=new QLineEdit(this);
    edit_pd->move(230,260);
    edit_pd->setPlaceholderText("密码");
    edit_pd->setEchoMode(QLineEdit::Password);

    //登录按钮
    btn_up=new QPushButton(QIcon(":/icon/denglu_1.png"),"登录",this);
    btn_up->move(180,310);
    connect(btn_up,SIGNAL(clicked()),this,SLOT(my_slot()));  //将登录点击与登录触发槽函数绑定
    //取消按钮
    btn_cancle=new QPushButton(QIcon(":/icon/quxiao.png"),"取消",this);
    btn_cancle->move(305,310);
    connect(btn_cancle,&QPushButton::clicked,this,&Widget::close);

}

Widget::~Widget()
{
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值