title: Passing a QLocalSocket* to a method expecting a QIODevice*
body: <p>Perhaps I'm being over-ambitious, but I'm trying to write a server program which can accept connections over both QLocalSockets and QTcpSockets. The concept is to have a 'nexus' object with both a QLocalServer and QTcpServer listening for new connections:</p>
  
  <pre><code>    Nexus::Nexus(QObject *parent)
          : QObject(parent)
      {
          // Establish a QLocalServer to deal with local connection requests:
          localServer = new QLocalServer;
  
          connect(localServer, SIGNAL(newConnection()),
                  this,        SLOT(newLocalConnection()));
          localServer -&gt; listen("CalculationServer");
  
  
          // Establish a UDP socket to deal with discovery requests:
          udpServer = new QUdpSocket(this);
          udpServer -&gt; bind(QHostAddress::Any, SERVER_DISCOVERY_PORT);
          connect(udpServer, SIGNAL(readyRead()),
                  this,      SLOT(beDiscovered()));
  
          // Establish a QTcpServer to deal with remote connection requests:
          tcpServer = new QTcpServer;
  
          connect(tcpServer, SIGNAL(newConnection()),
                  this,      SLOT(newTcpConnection()));
          tcpServer -&gt; listen(QHostAddress::Any, SERVER_COMMAND_PORT);
      }
  </code></pre>
  
  <p>... and then separate slots which establish a server object, whose constructor takes a pointer to a QIODevice. In theory, this <em>ought</em> to work because both QLocalSocket and QTcpSocket inherit QIODevice. Here is the newLocalConnection slot, for example:</p>
  
  <pre><code>void Nexus::newLocalConnection()
  {
      // Create a new CalculationServer connected to the newly-created local socket:
      serverList.append(new CalculationServer(localServer -&gt; nextPendingConnection()));
  
      // We don't allow more than one local connection, so stop listening on the server:
      localServer -&gt; close();
  }
  </code></pre>
  
  <p>The problem is that this won't compile, giving an error:</p>
  
  <blockquote>
    <p>error C2664:
    'CalculationServer::CalculationServer(QIODevice
    *,QObject *)' : cannot convert parameter 1 from 'QLocalSocket *' to
    'QIODevice *' 1>        Types pointed
    to are unrelated; conversion requires
    reinterpret_cast, C-style cast or
    function-style cast</p>
  </blockquote>
  
  <p>Now the types pointed to are clearly <em>not</em> unrelated, and elsewhere in my code I have no problems at all with actions like:</p>
  
  <pre><code>QLocalSocket *socket = new QLocalSocket;
  QIODevice    *server = new QIODevice;
  
  server = socket;
  </code></pre>
  
  <p>... so can anyone tell me why the compiler has a problem with this? Is there a way that I can make the constructor accept the QLocalServer*? I suppose there is the nuclear option of getting the constructor to take a void pointer plus an extra variable to tell it what it's being sent, so it can then recast the void pointer to either a QLocalSocket or QTcpSocket, but I feel uncomfortable resorting to reinterpret_cast on what looks like it ought to be a straightforward bit of C++ polymorphism.</p>
  
  <p>Regards,</p>
  
  <p>Stephen.</p>