PDA

View Full Version : Newbie signal-slot problems in a tcp server-client app



neoclaw
31st May 2010, 09:38
First I would like to say; I'm new to Qt, so this may be a simple question.

I'm trying to make a simple tcp server/client application, where the client can send a string to the server. My problem is that I want a list of connected clients, and if a client disconnect it should be remove from the list.

Any ideas on how to do that?

I tried the following:
The function to remove the client from the list

void Server::removeClient(QString address)
{
for(int i = 0; i < clientList.size(); i++)
{
if(strcmp(clientList.at(i).toAscii(), address.toAscii()) == 0)
{
clientList.removeAt(i);
}
}
}

The signal-slot thing

connect(client, SIGNAL(disconnected()),
this, SLOT(removeClient(const QString &)));

I don't know if I did it right since I'm new to the whole Qt thing. But I get this error:
Object::connect: No such slot Server::removeClient(QString &)

Lykurg
31st May 2010, 09:48
Read about signals and slots in the documentation. You need to declare your function as a slot. Use the Q_OBJECT makro. (And I guess in your case the arguments of signal and slot should match!)

squidge
31st May 2010, 10:00
Since you also have a list of clients, you might find QSignalMapper usefull too.