⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cpp

📁 Linux窗口程序设计,Qt4精彩实例分析,以循序渐进的方式介绍Qt4开发及其实例子,第一部分
💻 CPP
字号:
#include <QtNetwork>#include "server.h"Server::Server(QObject *parent,int port)    : QTcpServer(parent){	listen(QHostAddress::Any,port);}void Server::incomingConnection(int socketDescriptor){	TcpClientSocket *tcpClientSocket = new TcpClientSocket(this);	connect(tcpClientSocket,SIGNAL(updateClients(QString,int)),this,SLOT(updateClients(QString,int)));	connect(tcpClientSocket,SIGNAL(disconnected(int)),this,SLOT(slotDisconnected(int)));	    tcpClientSocket->setSocketDescriptor(socketDescriptor);	tcpClientSocketList.append(tcpClientSocket);}void Server::updateClients(QString msg,int length){	emit updateServer(msg,length);	for(int i=0;i<tcpClientSocketList.count();i++)	{		QTcpSocket *item=tcpClientSocketList.at(i);    	if(item->write(msg.toLatin1(), length)!=length)    	{    		continue ;    	}		}}void Server::slotDisconnected(int descriptor){	for(int i=0;i<tcpClientSocketList.count();i++)	{		QTcpSocket *item=tcpClientSocketList.at(i);    	if(item->socketDescriptor ()==descriptor)    	{    		tcpClientSocketList.removeAt(i);    		return;    	}		}		return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -