Is something like this what you were talking about?

Qt Code:
  1. //.h
  2. struct struct_ClientSocket
  3. {
  4. QTcpSocket *pClientSocket;
  5. QString str_ClientAddress;
  6. int nPort;
  7. };
  8.  
  9. private:
  10. QList<struct_ClientSocket> m_lst_pClientSockets;
  11.  
  12. private slots:
  13. void SetIncomingSocket();
  14. void OnSocketDestroyed();
  15. void ReadInputData();
  16.  
  17. //.cpp
  18. void CKeyboardLogAdmin::SetIncomingSocket()
  19. {
  20. QStringList str_lst_Name;
  21. QTcpSocket *tempSocket = pTcpServer->nextPendingConnection();
  22. struct_ClientSocket temp_struct_ClientSocket;
  23. temp_struct_ClientSocket.pClientSocket = tempSocket;
  24. temp_struct_ClientSocket.str_ClientAddress = tempSocket->peerAddress().toString();
  25. temp_struct_ClientSocket.nPort = tempSocket->peerPort();
  26. connect(tempSocket, SIGNAL(destroyed(QObject*)), this, SLOT(OnSocketDestroyed(QObject*)));
  27. connect(tempSocket, SIGNAL(disconnected()), tempSocket, SLOT(deleteLater()));
  28. connect(tempSocket, SIGNAL(readyRead()), this, SLOT(ReadInputData()));
  29. m_lst_pClientSockets.append(temp_struct_ClientSocket);
  30. }
  31.  
  32.  
  33.  
  34.  
  35. void CKeyboardLogAdmin::OnSocketDestroyed(QObject *obj)
  36. {
  37. for (int nSock = 0; nSock < m_lst_pClientSockets.size(); nSock++)
  38. {
  39. if (m_lst_pClientSockets[nSock].pClientSocket == obj)
  40. {
  41. m_lst_pClientSockets.removeAt(nSock);
  42. break;
  43. }
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. void CKeyboardLogAdmin::ReadInputData()
  51. {
  52. m_str_ReadData.clear();
  53. QByteArray ba_ByteData;
  54. int nSocket;
  55. if (m_lst_pClientSockets.size() > 0)
  56. {
  57. for (nSocket = 0; nSocket < m_lst_pClientSockets.size(); nSocket++)
  58. {
  59. if (m_lst_pClientSockets[nSocket].pClientSocket->bytesAvailable() > 0)
  60. {
  61. break;
  62. }
  63. }
  64. if (nSocket < m_lst_pClientSockets.size())
  65. {
  66. while (m_lst_pClientSockets[nSocket].pClientSocket->bytesAvailable() > 0)
  67. {
  68. ba_ByteData = m_lst_pClientSockets[nSocket].pClientSocket->readAll();
  69. }
  70. const char* ch_Data = ba_ByteData.data();
  71. m_str_ReadData = QString(ch_Data);
  72. QStringList str_lst_ReadData = m_str_ReadData.split("\t");
  73. if (!str_lst_ReadData.isEmpty())
  74. {
  75. if (str_lst_ReadData.first().compare(tr("LoginUser")) == 0)
  76. {
  77. ProcessLoginUserData(str_lst_ReadData);
  78. }
  79. if (str_lst_ReadData.first().compare(tr("LoginGuests")) == 0)
  80. {
  81. ProcessLoginGuests(str_lst_ReadData);
  82. }
  83. else if (str_lst_ReadData.first().compare(tr("Logout")) == 0)
  84. {
  85. ProcessLogoutData(str_lst_ReadData);
  86. }
  87. else if (str_lst_ReadData.first().compare(tr("ScreenLock")) == 0)
  88. {
  89. ProcessScreenLockData((str_lst_ReadData));
  90. }
  91. else if (str_lst_ReadData.first().compare(tr("ScreenUnlock")) == 0)
  92. {
  93. ProcessScreenUnlockData(str_lst_ReadData);
  94. }
  95. else if (str_lst_ReadData.first().compare(tr("AccountLogout")) == 0)
  96. {
  97. ProcessComputerUserAccountLogoutData(str_lst_ReadData);
  98. }
  99. else if (str_lst_ReadData.first().compare(tr("ValidatePin")) == 0)
  100. {
  101. ProcessValidatePinData(str_lst_ReadData);
  102. }
  103. else if (str_lst_ReadData.first().compare(tr("SessionLogoff")) == 0)
  104. {
  105. ProcessSessionLogoff(str_lst_ReadData);
  106. }
  107. }
  108. }
  109. }
  110. }
To copy to clipboard, switch view to plain text mode