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

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.
  • H Offline
    H Offline
    Hannes T
    wrote on 28 Mar 2016, 17:07 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 28 Mar 2016, 17:47 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.

      H 1 Reply Last reply 28 Mar 2016, 20:02
      1
      • M mrjj
        28 Mar 2016, 17:47

        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.

        H Offline
        H Offline
        Hannes T
        wrote on 28 Mar 2016, 20:02 last edited by
        #3

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

        1 Reply Last reply
        1

        1/3

        28 Mar 2016, 17:07

        • Login

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