Results 1 to 3 of 3

Thread: Newbie signal-slot problems in a tcp server-client app

  1. #1
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Newbie signal-slot problems in a tcp server-client app

    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
    Qt Code:
    1. void Server::removeClient(QString address)
    2. {
    3. for(int i = 0; i < clientList.size(); i++)
    4. {
    5. if(strcmp(clientList.at(i).toAscii(), address.toAscii()) == 0)
    6. {
    7. clientList.removeAt(i);
    8. }
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    The signal-slot thing
    Qt Code:
    1. connect(client, SIGNAL(disconnected()),
    2. this, SLOT(removeClient(const QString &)));
    To copy to clipboard, switch view to plain text mode 

    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 &)

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Newbie signal-slot problems in a tcp server-client app

    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!)

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie signal-slot problems in a tcp server-client app

    Since you also have a list of clients, you might find QSignalMapper usefull too.

Similar Threads

  1. tcp QT server - .Net c# client
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2010, 22:15
  2. Client Server
    By electronicboy in forum General Programming
    Replies: 3
    Last Post: 29th October 2009, 10:10
  3. [PyQt4] SSL server and client example
    By JoelG90 in forum Newbie
    Replies: 1
    Last Post: 24th May 2009, 09:09
  4. [newbie] signal/slot with sublassing problem
    By borker in forum Qt Programming
    Replies: 7
    Last Post: 17th April 2009, 13:44
  5. client-server how?
    By nongentesimus in forum Newbie
    Replies: 6
    Last Post: 28th November 2006, 09:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.