📄 loginform.cpp
字号:
/****************************************************************************** Form implementation generated from reading ui file 'loginForm.ui'**** Created by: The User Interface Compiler ($Id: qt/main.cpp 3.3.8 edited Jan 11 14:47 $)**** WARNING! All changes made in this file will be lost!****************************************************************************/#include "loginForm.h"#include <qvariant.h>#include <qlabel.h>#include <qlineedit.h>#include <qpushbutton.h>#include <qlayout.h>#include <qtooltip.h>#include <qwhatsthis.h>#include <qimage.h>#include <qpixmap.h>/* * Constructs a loginForm as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */loginForm::loginForm(Socket &s, QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ),sock(s){ if ( !name ) setName( "loginForm" ); idlable = new QLabel( this, "idlable" ); idlable->setGeometry( QRect( 40, 40, 30, 31 ) ); pswdlable = new QLabel( this, "pswdlable" ); pswdlable->setGeometry( QRect( 40, 110, 60, 31 ) ); idTxt = new QLineEdit( this, "idTxt" ); idTxt->setGeometry( QRect( 100, 40, 170, 30 ) ); resetBtn = new QPushButton( this, "resetBtn" ); resetBtn->setGeometry( QRect( 40, 170, 51, 41 ) ); okBtn = new QPushButton( this, "okBtn" ); okBtn->setGeometry( QRect( 130, 170, 60, 41 ) ); quitBtn = new QPushButton( this, "quitBtn" ); quitBtn->setGeometry( QRect( 230, 170, 51, 41 ) ); pswdTxt = new QLineEdit( this, "pswdTxt" ); pswdTxt->setGeometry( QRect( 100, 111, 170, 30 ) ); pswdTxt->setEchoMode( QLineEdit::Password ); languageChange(); resize( QSize(391, 239).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); // signals and slots connections connect( resetBtn, SIGNAL( clicked() ), idTxt, SLOT( clear() ) ); connect( resetBtn, SIGNAL( clicked() ), pswdTxt, SLOT( clear() ) ); connect( resetBtn, SIGNAL( clicked() ), idTxt, SLOT( setFocus() ) ); connect( quitBtn, SIGNAL( clicked() ), this, SLOT( Quit() ) ); connect( quitBtn, SIGNAL( clicked() ), this, SLOT( close() ) ); connect( okBtn, SIGNAL( clicked() ), this, SLOT( GetTxt() ) ); connect( this, SIGNAL( toSendId() ), this, SLOT( SendId() ) ); connect( this, SIGNAL( toSendPswd() ), this, SLOT( SendPswd() ) ); connect( this, SIGNAL( toGetSerMsg() ), this, SLOT( GetSerMsg() ) ); connect( this, SIGNAL( toRetry() ), idTxt, SLOT( clear() ) ); connect( this, SIGNAL( toRetry() ), pswdTxt, SLOT( clear() ) ); connect( this, SIGNAL( toRetry() ), idTxt, SLOT( setFocus() ) ); // tab order setTabOrder( idTxt, pswdTxt ); setTabOrder( pswdTxt, okBtn ); setTabOrder( okBtn, resetBtn ); setTabOrder( resetBtn, quitBtn );}/* * Destroys the object and frees any allocated resources */loginForm::~loginForm(){ // no need to delete child widgets, Qt does it all for us if(fchat->IsQuited()) { if(fchat) delete fchat; fchat=NULL; }}/* * Sets the strings of the subwidgets using the current * language. */void loginForm::languageChange(){ setCaption( tr( "Login" ) ); idlable->setText( tr( "ID :" ) ); pswdlable->setText( tr( "Password :" ) ); resetBtn->setText( tr( "&Reset" ) ); resetBtn->setAccel( QKeySequence( tr( "Alt+R" ) ) ); okBtn->setText( tr( "&OK" ) ); okBtn->setAccel( QKeySequence( tr( "Alt+O" ) ) ); quitBtn->setText( tr( "&Quit" ) ); quitBtn->setAccel( QKeySequence( tr( "Alt+Q" ) ) );}void loginForm::GetTxt(){ id=idTxt-> text(); pswd=pswdTxt-> text(); if(id!="") { emit toSendId(); } }void loginForm::SendId(){ sock.SendMsg(id); sleep(1); emit toSendPswd();}void loginForm::SendPswd(){ sock.SendMsg(pswd); sleep(1); emit toGetSerMsg();}void loginForm::GetSerMsg(){ char* msg=new char[15]; msg=sock.GetMsg(); msg[strlen(msg)+1]='\0'; cout<<msg<<endl; if((strncmp(msg,"ok",2))==0) { cout<<"Login succeed\nClose loginform"<<endl; fchat=new chatForm(sock); if(fchat) { cout<<"Welcome to chat room"<<endl; fchat->setCaption( id ); fchat->Show(); delete msg; msg=NULL; this->close(); } } else { QMessageBox::information( this, "Login", "ID or Password Error!\n" "Please check!" ); delete msg; msg=NULL; emit toRetry(); }}void loginForm::Quit(){ sock.SendMsg("quit"); sock.CloseSocket(); cout<<"Close socket"<<endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -