Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't use the socket descriptor of a <code>QTcpSocket</code> object if it is already used by another <code>QTcpSocket</code> object. There is also no method of de-assigning it once is assigned to a <code>QTcpSocket</code></p> <p>Even if you don't explicitly use the initial <code>QTcpSocket</code>, if there is an event loop in the thread it was created (which is probably the case here), Qt will monitor it in that thread.</p> <p>As an alternative, you could:</p> <ul> <li>derive the <code>QTcpServer</code> class to redefine its <a href="http://qt-project.org/doc/qt-4.8/qtcpserver.html#incomingConnection" rel="nofollow"><code>incomingConnection(int socketDescriptor)</code></a> method to get that descriptor before it is assigned to a <code>QTcpSocket</code> instead of using <code>nextPendingConnection</code> <strong>OR</strong></li> <li><p>pass directly the <code>QTcpSocket</code> you receive from <code>nextPendingConnection</code> instead of the socket descriptor as a parameter to the thread constructor, and move it to the other thread (see <a href="http://qt-project.org/doc/qt-4.8/qtcpserver.html#notes" rel="nofollow">that note</a>):</p> <pre><code>TCPConnectThread(QTcpSocket *socket) : m_socket(socket) { m_socket−&gt;setParent(0); // necessary to move the object to another thread m_socket-&gt;moveToThread(this); ... } </code></pre> <p>As the moving has to be done from the initial thread, the first alternative might be easier to do with a <code>QRunnable</code>, because you might not have access easily to the future <code>QThread</code> the runnable will be using.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload