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();
}

输出:

qt 简单登录界面(一)的更多相关文章

  1. Cookie案例:简单登录界面中的应用

    ServletDemo1.java package ztq.servlet.study; import java.io.IOException; import java.io.PrintWriter; ...

  2. 以java实现的一个简单登录界面(带验证码)

    本文参考于:https://blog.csdn.net/wyf2017/article/details/78831744 https://blog.csdn.net/MengKun822/articl ...

  3. Qt 用户登录界面

     使用QT创建自己的登录窗口: 主要步骤:    1.窗口界面的绘制     2.沟通数据库进行密码验证 void MainWindow::on_pushButton_clicked() { // 连 ...

  4. 一个基于QT简单登录对话框

    1. 登录对话框式样 2. QLoginDialog.h #ifndef DIALOG_H #define DIALOG_H #include <QtGui/QDialog> #inclu ...

  5. JSP内置对象的cookie和session实现简单登录界面

    创建一个index.jsp页面 <%@ page language="java" contentType="text/html; charset=utf-8&quo ...

  6. 一个基于QT简单登录对话框(带验证码功能)

    1. 对话框样式 2. 源代码 ①. main.cpp #include <QtGui/QApplication> #include "QLoginDialog.h" ...

  7. JAVA语言实现简单登录界面

    程序设计思想: 使用Math.random()方法循环生成6个97~122之间的随机整数(对应ASCII码值‘a’~‘z’),将其转化为char型变量,连接成为一个6位字符串作为验证码输出,提示用户输 ...

  8. 设计简单登录界面(Java web)

    程序设计思想: 在Input.jsp中创建一个表格里边分别是课程名称,任课老师,教学地点,并分别用三个文本框来接受输入的三个属性, 并传到另外的Jsp页面中,又来接受三个数据,并判断传来的教师,与教室 ...

  9. Java简单登录图形界面

    本文参考与:https://blog.csdn.net/wyf2017/article/details/78831744 https://blog.csdn.net/MengKun822/articl ...

随机推荐

  1. JAVA接收postman的中raw的参数

    /** * java获取raw */ public static String readRaw(InputStream inputStream) { String result = "&qu ...

  2. 【LeetCode】214. Shortest Palindrome 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 前缀是否回文 判断前缀 相似题目 参考资料 日期 题 ...

  3. 【LeetCode】209. Minimum Size Subarray Sum 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/minimum- ...

  4. 【LeetCode】535. Encode and Decode TinyURL 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 方法一:数组 方法二:字典 日期 题目地址:https://l ...

  5. golang切片的一些自问自答

    你好,我是轩脉刃.这篇是关于go切片的一些问题和回答. go的切片基本上是代码中使用最多的一种数据结构了,使用这种数据结构有哪些要注意的点,这个是非常必要了解的东西.基本上,以前写的一篇博客 http ...

  6. 解决Java保存到数据库中文乱码问题,加useUnicode=true&characterEncoding=UTF-8

    Java保存到数据库中文乱码, 解决方法如下: 我们在连接MySQL数据库的时候一般都会在url后面添加useUnicode=true&characterEncoding=UTF-8,但是问什 ...

  7. docker学习:docker三要素

    镜像 docker 镜像(image)就是一个只读的模板.镜像可以用来创建docker容器,一个镜像可以创建很多容器 容器 docker 利用容器(Container)独立运行的一个或者一组应用.容器 ...

  8. xpath如何使用正则、xpath定位svg标签、xpath常用集合

    自己用到的xpath都收集下咯!!! 持续更新本页面 xpath查找svg图标 xpath('//*[local-name() = "svg" and @class="_ ...

  9. Java 字符与字符串

    字符 // 定义字符 char c1 = 'a'; char c2 = '1'; char c3 = '中'; // 自动装箱 Character c = c1; // 自动拆箱 c1 = c; // ...

  10. Python_PyYaml模块的使用

    YAML是一种比XML和JSON更轻的文件格式,也更简单更强大,它可以通过缩进来表示结构. 模块安装 pip install pyyaml # 如果是py2,使用 pip install yaml P ...