PDA

View Full Version : communication between objects and tcpsockets



Begi
26th September 2011, 18:43
Can someone tell me a good solution how to communicate between client objects? In this case :how can i send a message from a single class of the client object to other Client objects with a message?
Its a server application and here is the code:


Server::Server(QObject *parent) :
QTcpServer(parent)
{

!this->listen(QHostAddress::Any,2234))

this->threadpool = new QThreadPool(this);
threadpool->setMaxThreadCount(10);
threadpool->setExpiryTimeout(30000);

}

Server::~Server(){

this->close();

}

void Server::incomingConnection(int handle){

Client * client = new Client();
klient->setAutoDelete(false);

client->setSocketDescriptor(handle);
this->threadpool->tryStart(client);


}

Client class:

void Client::run(){
connect(this,SIGNAL(readyRead()),this,SLOT(readDat a()));


}


void Client::readData(){

//reading and sending forward to all objects of this class

}


Is it possible and a good solution to create a static member QList<Client*> and iterate inside the
readyread funcion to gaina all objects of that class and post an event? SOmething like that:


void Client::readData(){

Client * tmp = iterating QList<Client*>
{
QCoreApplication::postEvent(tmp,NewMyEvent(message ));

}


}

high_flyer
28th September 2011, 15:29
have a look at this example:
http://doc.qt.nokia.com/4.7-snapshot/network-fortuneclient.html