title: How to compare IP of the requested client connection to one of the recognized IP's in QTcpSocket class?
body: <p>My <strong>main issue</strong> is: I have a list of recognised IPs and I am carrying out Multi threaded TCP Client-Server Communication; so whenever a new connection request comes from any random client (server is constantly listening), I want to first compare that IP to the stored IP's and allow a new connection only if it is one of my recognised IP's. There can be a .txt file on hard disk or a <strong><em>QList</em></strong> or <strong><em>QString</em></strong> whichever is a better soluion.</p>
  
  <p><strong>EDIT</strong>: To make myself clear, Following is the <strong><em>server.cpp</em></strong> file I've developed so far and the errors I am confronted with at the moment.</p>
  
  <pre><code>#include "myserver.h"
  #include "ioprogram.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  //string ClientInfo;
  
  MyServer::MyServer(QObject *parent): QTcpServer(parent)
  {
      QStringList accepted_ip_list;   //List of remote IPs that can be accepted in QString list format
      accepted_ip_list.append("127.0.0.1");   // IPv4 local address
      accepted_ip_list.append("::1");         // IPv6 local address
  
      // Convert from QString to integer format, generating new list
      foreach (const QString &amp;ip, accepted_ip_list)
      {
          QHostAddress host_address(ip);
          my_accepted_ip_list.append(host_address);
      }
  
      myserver = new QTcpServer(this);
  
      connect(myserver, &amp;QTcpServer::incomingConnection, this, &amp;MyServer::incomingConnection);
  
      myserver-&gt;listen(QHostAddress::Any, 1234);
  }
  
  void MyServer::startServer()
  {
      if(!this-&gt;listen(QHostAddress::Any,1234))
      {
          qDebug() &lt;&lt; "Could not start server.";
      }
      else
      {
          qDebug() &lt;&lt; "Listening...";
      }
  }
  
  void MyServer::incomingConnection(qintptr socketDescriptor)
  {
      qDebug() &lt;&lt; socketDescriptor &lt;&lt; "Connecting...";
  
      while (myserver-&gt;hasPendingConnections())
      {
          QTcpSocket *socket = myserver-&gt;nextPendingConnection();
          QHostAddress host_address = socket-&gt;peerAddress();
  
          bool contains = false;
  
          for(int i=0; i &lt; my_accepted_ip_list.size(); i++)
          {
              if(my_accepted_ip_list[i].isEqual(host_address,QHostAddress::ConvertV4MappedToIPv4))
              {
                  contains = true;
                  break;
              }
          }
  
          if(contains)
          {
              MyThread *thread = new MyThread(socketDescriptor, this);
  
              connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
              thread-&gt;start();
          }
          else
          {
              socket-&gt;abort();        // Reject peer by disconnecting it
              socket-&gt;deleteLater();  // Schedule the socket removal from memory
          }
      }
  }
  </code></pre>
  
  <p>And here are the errors:</p>
  
  <p><strong>1)</strong> @line10 --- prototype for 'MyServer::MyServer(QObject*)' does not match any in class 'MyServer'</p>
  
  <p><strong>2)</strong> @line55 --- class 'QHostAddress' has no member named 'isEqual'</p>
  
  <p><strong>3)</strong> @line55 --- 'ConvertV4MappedToIPv4' is not a member of 'QHostAddress'</p>
  
  <p>and here is the header file:</p>
  
  <pre><code>#ifndef MYSERVER_H
  #define MYSERVER_H
  
  #include &lt;QTcpServer&gt;
  #include &lt;QDebug&gt;
  #include "mythread.h"
  //#include "ioprogram.h"
  
  class MyServer : public QTcpServer
  {
      Q_OBJECT
  public:
      explicit MyServer(QTcpServer *parent = nullptr);
      void startServer();
  
  signals:
  
  private slots:
  //    void newConnection();
  
  private:
      QTcpServer *myserver;
      QList&lt;QHostAddress&gt; my_accepted_ip_list;    //List of IPv4 addresses allowed by the server, in quint32 not QString
  
  protected:
      void incomingConnection(qintptr socketDescriptor);
  };
  #endif // MYSERVER_H
  </code></pre>
  
  <p>and here is one <strong>error</strong> in the header file:
  candidates are: MyServer::MyServer(MyServer&amp;&amp;)</p>