freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于qt簡單聊天程序-具體步驟-詳細注釋(已修改)

2025-05-23 18:50 本頁面
 

【正文】 基于 qt 編寫的 c/ s 模型的簡單聊天程序 開發(fā) Qt 工具 一 .創(chuàng)建工程 1,選擇新建工程 2 選擇 Qt4 Gui Application 工程。 (帶 UI 界面編輯的工程 ) 3 取工程名 C_S_Socket。路徑隨意 ,不要有任何中文 Next 4 默認即可, Next(這是為此次工程選擇要添加的頭文件。我們不需要其他的功能。默認) 5 Base class 選擇 QDialog。 Class name 改 MainDlg。 Next(我們是基于 Qt 界面編程的嘛。所以就選 QDialog Qt 窗口 類噻) 6 Finish 完成 (這里是編輯器告訴我們生成了如下文件 ) 二 .畫界面 1 點擊 進入主界面窗體設(shè)計成如下 2 設(shè)置各個控件的對象名 (不能同名,系統(tǒng)用對象名找到控件。命名規(guī)范方便自己識別 ) { 服務(wù)器單選框: radioButton_Server 客戶端單選框: radioButton_Client IP 地址框: lineEdit_Address 用戶名框: lineEdit_Name 離開按鈕: wayButton 進入按鈕: enterButton } 3 創(chuàng)建一個窗體類,用于發(fā)送接收信息的窗體 選擇窗體樣式。 修改類名 chat,下一步完成 ~(chat:聊天的意思 ) 4 第二窗體設(shè)計如下 窗體控件對象名如下 { 顯示信息框: showMessageEdit 輸入信息框: writeMessageEdit 用戶名顯示列表: onlineMessageList 關(guān)于按鈕: aboutButton 發(fā)送按鈕: sendButton } 界面等操作到此結(jié)束?。?2021 年 12 月 8 日 16:47:31 代碼貼在后面。 注意: 代碼寫完后 編譯會出錯!在 工程文件的最后加上 QT += work 編譯就不會出錯了 (不知道什么意思,難道是為 Qt 加入網(wǎng)絡(luò)的支持? ) 代碼 ifndef MAINDLG_H define MAINDLG_H include QDialog namespace Ui { class MainDlg。 } class MainDlg : public QDialog { Q_OBJECT public: MainDlg(QWidget *parent = 0)。 ~MainDlg()。 bool m_bool_server。//判斷選擇的方式 protected: void changeEvent(QEvent *e)。 void showChatWindow()。 void sendEnterMessage(QString, QString)。 private: Ui::MainDlg *ui。 public void enterSlot()。 void OnSelectServer()。 void OnSelectClient()。 }。 endif // MAINDLG_H include include include QMessageBox MainDlg::MainDlg(QWidget *parent) : QDialog(parent), ui(new Ui::MainDlg) { uisetupUi(this)。 //離開按鈕點擊事件的連接 connect(uiawayButton, SIGNAL(clicked()),qApp, SLOT(quit()))。 //進入按鈕點擊事件的連接 connect(uienterButton, SIGNAL(clicked()), this, SLOT(enterSlot()))。 //選擇服務(wù)器單選按鈕點擊事件的連接 connect(uiradioButton_Server, SIGNAL(clicked()), this, SLOT(OnSelectServer()))。 //選擇客戶端單選按鈕點擊事件的連接 connect(uiradioButton_Client, SIGNAL(clicked()), this, SLOT(OnSelectClient()))。 } MainDlg::~MainDlg() { delete ui。 } /* *選擇服務(wù)器單選按鈕的點擊消息 */ void MainDlg::OnSelectServer() { m_bool_server = true。 uilineEdit_AddresssetText()。 if (uilineEdit_Nametext().isEmpty()|| uilineEdit_Nametext()==Client) uilineEdit_NamesetText(Server)。 } /* *選擇客戶端單選按鈕的點擊消息 */ void MainDlg::OnSelectClient() { m_bool_server = false。 uilineEdit_AddresssetText()。 if (uilineEdit_Nametext().isEmpty() || uilineEdit_Nametext()==Server) uilineEdit_NamesetText(Client)。 } void MainDlg::changeEvent(QEvent *e) { QDialog::changeEvent(e)。 switch (etype()) { case QEvent::LanguageChange: uiretranslateUi(this)。 break。 default: break。 } } void MainDlg::enterSlot() { if (uilineEdit_Nametext().isEmpty()) { QMessageBox mess。 (QFont(Sans Serif, 12, 50))。 (this, QString::fromLocal8Bit(出錯 ), QString::fromLocal8Bit(font size=5請輸入正確的昵稱 ,謝謝 !/font))。 return。 } //發(fā)射信號 emit sendEnterMessage(uilineEdit_Nametext(), uilineEdit_Addresstext())。 emit showChatWindow()。 } ifndef CHAT_H define CHAT_H include QDialog include include QDateTime include QtNetwork/QTcpServer//Tcp 協(xié)議的服務(wù)器監(jiān)聽連接類 include QtNetwork/QTcpSocket//Tcp 協(xié)議的 Socket 類 include QtNetwork/QHostAddress namespace Ui { class chat。 } class chat : public QDialog { Q_OBJECT public: chat(QWidget *parent = 0)。 ~chat()。 void socketServer()。//啟動服務(wù)器監(jiān)聽連接 void socketClient(QString host)。//與服務(wù)器連接 MainDlg *p_my_dlg。//主界面指針 int port。//端口號 QString m_str_userName。//用戶名 bool m_bool_server。//是服務(wù)器還是客戶端 //Tcp 協(xié)議的服務(wù)器 Socket 類 QTcpServer *m_p_server。//Tcp 協(xié)議的服務(wù)器監(jiān)聽連接類 QTcpSocket *m_p_serverSocket。//服務(wù)器 Socket QTcpSocket *m_p_clientSocket。//客戶端 Socket QDateTime nowDateTime。//時間 protected: void changeEvent(QEvent *e)。 private: Ui::chat *ui。 public void showAndHideSlot()。//顯示本窗體關(guān)閉主窗體 void changeButtonStateSlot()。//如果輸入框為空,則發(fā)送按鈕不能使用 void createAboutSlot()。//關(guān)于 信息 void enterSlot(QString name, QString host)。//選擇服務(wù)器或客戶端 void newConnectionSlot()。//連接來時,服務(wù)器與客戶端創(chuàng)建連接 void newDataSlot()。//有數(shù)據(jù)來時 void deleNameSlot()。// void addSlot()。 void appendMessageSlot()。 }。 endif // CHAT_H include include include QMessageBox chat::chat(QWidget *parent) : QDialog(parent), ui(new Ui::chat) { uisetupUi(this)。//設(shè)置 UI 設(shè)計的界面的控件 m_p_server = NULL。 m_p_serverSocket = NULL。 m_p_clientSocket = NULL。 p_my_dlg = new MainDlg。//主界面 p_my_dlgshow()。 //顯示主界面 /* *連接信號 */ //主窗體中顯示本窗體信號 connect(p_my_dlg, SIGNAL(showChatWindow()), this, SLOT(showAndHideSlot()))。 connect(p_my_dlg, SIGNAL(sendEnterMessage(QString , QString)), this,SLOT(enterSlot(QString , QString )))。 connect(uiwriteMessageEdit, SIGNAL(textChanged()), this, SLOT(changeButtonStateSlot()))。 connect(uiaboutButton, SIGNAL(clicked()), this, SLOT(createAboutSlot()))。 connect(uisendButton, SIGNAL(clicked()), this, SLOT(appendMessageSlot()))。 } chat::~chat() { delete ui。 } //本窗體創(chuàng)建時由系統(tǒng)自動
點擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計相關(guān)推薦
文庫吧 www.dybbs8.com
公安備案圖鄂ICP備17016276號-1