资源描述:
《基于qt编写的c/s模型的简单聊天程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、基于qt编写的c/s模型的简单聊天程序(借鉴别人的)2009-06-2711:29/*程序预览*/部分源码:/*login.cpp*/#include"login.h"LoginDialog::LoginDialog(){ setupUi(this); connect(awayButton,SIGNAL(clicked()),qApp,SLOT(quit())); connect(enterButton,SIGNAL(clicked()),this,SLOT(enterSlot()));}voidLoginDialog::enterSlot(){
2、if(lineEdit_2->text().isEmpty()) { QMessageBoxmess; mess.setFont(QFont("SansSerif",12,50)); mess.warning(this, QString::fromLocal8Bit("出错"), QString::fromLocal8Bit("请输入正确的昵称,谢谢!")); return; } emitsendEnterMessa
3、ge(lineEdit_2->text(),lineEdit_3->text()); emitshowChatWindow();}voidLoginDialog::closeEvent(QCloseEvent*){ qApp->quit();}/*chat.cpp*/#include"chat.h"Chat::Chat(){ serverSocket=NULL; server=NULL; client=NULL; setupUi(this); login=newLoginDialog; login->show(); conne
4、ct(login,SIGNAL(showChatWindow()),this,SLOT(showAndHideSlot())); connect(login,SIGNAL(sendEnterMessage(QString,QString)), this,SLOT(enterSlot(QString,QString))); connect(writeMessageEdit,SIGNAL(textChanged()),this,SLOT(changeButtonStateSlot())); connect(aboutButton,SI
5、GNAL(clicked()),this,SLOT(createAboutSlot())); connect(sendButton,SIGNAL(clicked()),this,SLOT(appendMessageSlot())); connect(quitButton,SIGNAL(clicked()),qApp,SLOT(quit()));}voidChat::showAndHideSlot(){ deletelogin; this->show();}voidChat::createAboutSlot(){}voidChat::enter
6、Slot(QStringname,QStringhost){ port=22222; if(host.isEmpty()) { socketServer(); } else { socketClient(host); } userName=name; onlineMessageList->addItem(name);}voidChat::changeButtonStateSlot(){ boolboo_dis=writeMessageEdit->toPlainText(
7、).isEmpty(); sendButton->setDisabled(boo_dis);}voidChat::appendMessageSlot(){ QStringcontent=writeMessageEdit->toPlainText(); if(content.isEmpty()) { QMessageBox::warning(this,"出错",QString::fromLocal8Bit("发送的内容不能为空")); return; } nowDateTime=QDateTime