QT登陆窗口代码
2012-12-09 16:05
162 查看
#include "dialog.h" #include "ui_dialog.h" #include "QtGui" #include "mysql/mysql.h" #include<cstdio> #include<cstring> #include<string> using namespace std; Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog) { ui->setupUi(this); ui->pass->setEchoMode(QLineEdit::Password); this->setFixedSize(this->width(),this->height()); ui->user->setFocus(); ui->user->setMaxLength(16); //ui->user->setMaximumWidth(16); //ui->pass->setMaximumWidth(16); ui->pass->setMaxLength(16); } Dialog::~Dialog() { delete ui; } bool Dialog::judge(QString a,QString b,bool &flag) { MYSQL *con=mysql_init(NULL); MYSQL_RES *res=NULL; MYSQL_ROW row; string order(""); order+="select pass from userdata where user='"; order+=a.toStdString().c_str(); order+="'"; bool iserror; if(!con) { flag=true; QMessageBox::warning(this,tr("INIT ERROR!"),tr(mysql_error(con)),QMessageBox::Yes); return false; } con=mysql_real_connect(con,"127.0.0.1","root","root","qt",0,NULL,0); if(!con) { flag=true; QMessageBox::warning(this,tr("CONNECT ERROR!"),tr("Please check network!"),QMessageBox::Yes); return false; } iserror=mysql_query(con,order.c_str()); if(iserror) { flag=true; QMessageBox::warning(this,tr("QUERY ERROR!"),tr(mysql_error(con)),QMessageBox::Yes); return false; } else { res=mysql_use_result(con); if(res) { if((row=mysql_fetch_row(res))!=0) if(b.toStdString()==string(row[0]))return true; } } return false; } void Dialog::on_login_clicked() { bool flag=false; if(ui->user->text().isEmpty()||ui->pass->text().isEmpty()) { QMessageBox:: warning(this,tr("ERROR"),tr("Username or Password is empty!"),QMessageBox::Yes); if(ui->user->text().isEmpty()||(ui->user->text().isEmpty()&&ui->pass->text().isEmpty()))ui->user->setFocus(); else if(ui->pass->text().isEmpty())ui->pass->setFocus(); } else if(judge(ui->user->text(),ui->pass->text(),flag)) { accept(); } else { if(!flag) QMessageBox::warning(this,tr("EROOR"),tr("Username or Passwd Error!"),QMessageBox::Yes); ui->user->clear(); ui->pass->clear(); ui->user->setFocus(); } }
相关文章推荐
- 使用Qt Designer和手动编写代码两种方式实现多窗口切换程序(Qt基础)
- 【zz】C#登陆窗口设计及代码网址集
- Qt代码调整窗口初始大小
- Qt 代码: 子窗口调用父窗口
- Ext2.0:Ext登陆窗口代码 含验证码
- Qt登陆窗口,将登陆用户的信息显示到主界面中
- Qt布局管理: 分割窗口QSplitter类讲解(纯代码实现分割窗口)
- QT实现回车执行(例如登陆窗口)
- qt关闭窗口实现逐渐消失代码
- Qt 之 模仿 QQ登陆界面——旋转窗口篇
- Qt开发-简易浏览器+无边框阴影可移动可拖动窗口代码分享
- qt登陆窗口到主界面(一)
- Ext2.0:Ext登陆窗口代码 含验证码
- Qt学习记录3——登陆窗口的实现
- Qt布局管理: 分割窗口QSplitter类讲解(纯代码实现分割窗口)
- qt登陆窗口到主界面(二)
- Qt 代码: 子窗口调用父窗口(其实就是用指针直接访问)
- 让一层div遮住全窗口 另一层显示登陆框自动居中的css代码
- Qt 数据库、登陆界面练习代码
- jquery实现浮动在网页右下角的彩票开奖公告窗口代码