QT day2

1> 完成登录框的按钮操作,并在登录成功后进行界面跳转

2> 将模拟面试答案写在思维导图上

QT day2_第1张图片QT day2_第2张图片QT day2_第3张图片

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    Form f;
    //将第一个界面的信号函数与第二个界面的槽函数链接
    QObject::connect(&w,&Widget::jump,&f,&Form::jump_slot);
    close c;
    QObject::connect(&w,&Widget::close_jump,&c,&close::closewin);
    QObject::connect(&c,&close::mainjump,&w,&Widget::showmain);
    return a.exec();
}
/**************************************/
connect(btn2,&QPushButton::clicked,this,&Widget::login_slot);
    connect(btn3,SIGNAL(clicked()),this,SLOT(cancel_slot()));


}
void Widget::login_slot()
{
    if(this->edit1->text()=="admin" && this->edit2->text()=="123456")
    {
        qDebug() << "login success" ;
        this->close();
        emit jump();
    }
    else
    {
        qDebug() << "login fail" ;
        //edit1->clear();
        edit2->clear();
    }
}
void Widget::cancel_slot()
{
    this->close();
    emit close_jump();
}

void Widget::showmain()
{
    this->show();
}
/******************************/
void Form::jump_slot()
{
    this->show();
}
/************************************/
this->resize(500,300);
    lab2=new QLabel(this);
    lab2->resize(500,300);
    lab2->setPixmap(QPixmap(":/icon/liandao.jpg"));
    lab2->setScaledContents(1);


    btn1=new QPushButton("取消",this);
    btn2=new QPushButton("确认",this);
    btn1->resize(150,100);
    btn2->resize(150,100);
    btn1->move(100,150);
    btn2->move(300,150);
    btn1->setIcon(QIcon(":/icon/heart.png"));
    btn2->setIcon(QIcon(":/icon/heart.png"));
    /*****************************************/
    lab1=new QLabel(this);
    lab1->resize(200,100);
    lab1->setText("确认要退出吗?");
    lab1->setStyleSheet("background-color: rgb(0, 255, 255);"
                        "color: rgb(0, 0, 0);"
                        );
    /******************/
    connect(btn2,&QPushButton::clicked,this,&QWidget::close);
    connect(btn1,&QPushButton::clicked,this,&close::cancel_slot);
}

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

void close::closewin()
{
    this->show();
}

void close::cancel_slot()
{
    this->QWidget::close();
    emit mainjump();
}

xmind

QT day2_第4张图片

你可能感兴趣的:(c++,qt,开发语言)