• qt 简单登录界面(一)


    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    #include <QWidget>
    #include<QLineEdit>
    class Widget : public QWidget
    {
        Q_OBJECT
    public slots:
        void foo();
    public:
        Widget(QWidget *parent = 0);
        ~Widget();
        QLineEdit *userEdit;
        QLineEdit * passwdEdit;
    };
    
    #endif // WIDGET_H

    widget.cpp

    #include "widget.h"
    #include<QBoxLayout>
    #include<QGridLayout>
    #include<QPushButton>
    #include<QLabel>
    #include<QLineEdit>
    #include<QDebug>
    #include <QApplication>
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
            QGridLayout* grid=new  QGridLayout(this);
            QHBoxLayout* hbox=new QHBoxLayout(this);
            QPushButton *ok=new QPushButton("确认");
            QPushButton *cancel=new QPushButton("取消");
            QLabel *userLabel= new QLabel("用户:");
            userEdit=new QLineEdit;
            QLabel* passwdLabel=new QLabel("密码:");
            passwdEdit=new QLineEdit;
    
            passwdEdit->setEchoMode(QLineEdit::Password);
            grid->addWidget(userLabel,0,0,1,1);
            grid->addWidget(userEdit,0,1,1,1);
            grid->addWidget(passwdLabel,1,0,1,1);
            grid->addWidget(passwdEdit,1,1,1,1);
    
            hbox->addWidget(ok);
            hbox->addWidget(cancel);
    
            grid->addLayout(hbox,2,0,1,2);
            this->setLayout(grid);
    
            connect(cancel,SIGNAL(clicked()),this,SLOT(close()));
            connect(ok,SIGNAL(clicked()),this,SLOT(foo()));
    
    }
    void Widget::foo()
    {
        if(userEdit->text()=="admin")
        {
            if(passwdEdit->text()=="123456")
            {
                qDebug()<<"登录成功"<<endl;
            }
            else
            {
              qDebug()<<"密码错误"<<endl;
            }
        }
        else {
            qDebug()<<"用户名不存在"<<endl;
        }
    }
    Widget::~Widget()
    {
    
    }

    main.cpp:

    #include "widget.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.resize(500,300);
        w.show();
    
        return a.exec();
    }

    输出:

  • 相关阅读:
    c++ vector容器的使用,序列倒叙reverse(),容器底部插入一个数值push_back()
    vs2015+opencv-3.2.0-vc14配置
    串的匹配算法--C语言实现
    顺序队列与链式队列--C语言实现
    链式栈-C语言实现
    顺序栈与两栈共享空间-C语言实现
    静态链表-C语言实现
    循环双向链表-C语言实现
    链表-C语言实现
    顺序表-C语言实现
  • 原文地址:https://www.cnblogs.com/SunShine-gzw/p/13262177.html
Copyright © 2020-2023  润新知