Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++ Multi-Client TCP Server with QList
QtWS25 Last Chance

C++ Multi-Client TCP Server with QList

Scheduled Pinned Locked Moved Solved General and Desktop
tcp serversignal & slotqlisttcptcpsocket
3 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Hannes TH Offline
    Hannes TH Offline
    Hannes T
    wrote on last edited by
    #1

    Necessary informations:

      QList<QTcpSocket*> list;
      QTcpServer* server;
      QTcpSocket* socket;
    

    In Qt I have built a TCP-Server(QTcpServer)! I have a **QList **with all my connected clients and I want to read the incomming data for each client personally. So if the **QTcpServer **gets a new connection, I handel it like this:

    void Server::newConnection()
    {
       qDebug() << "New Connection";
       list.append(server->nextPendingConnection());
       connect(list.last(),SIGNAL(readyRead()),this,SLOT(readyRead()));
    }
    

    How can I get the correct client (out of my QList), which send the **SIGNAL **readyRead(), in my **SLOT **readyRead()?

    void Server::readyRead(){
           //??
    }
    

    Any help is welcomed!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi and welcome
      In the slot, you can call sender() to know who sent the signal.
      Its returns as QObject so you must cast it.

      QTcpSocket* soc = qobject_cast<QTcpSocket*>(sender());
      if(soc) ...

      Remember to check that pointer is not NULL.

      Hannes TH 1 Reply Last reply
      1
      • mrjjM mrjj

        hi and welcome
        In the slot, you can call sender() to know who sent the signal.
        Its returns as QObject so you must cast it.

        QTcpSocket* soc = qobject_cast<QTcpSocket*>(sender());
        if(soc) ...

        Remember to check that pointer is not NULL.

        Hannes TH Offline
        Hannes TH Offline
        Hannes T
        wrote on last edited by
        #3

        @mrjj Thank you a lot, it works!!!

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved