tbscope is right...
When you connect proxyServer::newConnection and WebProxy::go(), they are on the same thread, so it is a direct connection. When this happens, Qt doesn't fill up the sender() value... so, when you do it in your wpt->start(), which calls run(), you are using a null value.
As a try, you can replace
QTcpServer *proxyServer
= qobject_cast<QTcpServer
*>
(sender
());
QTcpServer *proxyServer = qobject_cast<QTcpServer*>(sender());
To copy to clipboard, switch view to plain text mode
by
QTcpServer *proxyServer
= qobject_cast<QTcpServer
*>
(parent
());
QTcpServer *proxyServer = qobject_cast<QTcpServer*>(parent());
To copy to clipboard, switch view to plain text mode
BTW, I think you will need at least one mutex to protect the following
QTcpServer *proxyServer
= qobject_cast<QTcpServer
*>
(sender
());
//this you should review QTcpSocket *socket
= proxyServer
->nextPendingConnection
();
QTcpServer *proxyServer = qobject_cast<QTcpServer*>(sender()); //this you should review
QTcpSocket *socket = proxyServer->nextPendingConnection();
To copy to clipboard, switch view to plain text mode
to avoid lost connections.
Try making this a piece of WebProxy implementation, instead of doing this in the thread start...
Or better: catch the nextPendigConnection, and pass it to constructor of the thread object (using socket descriptor, not sure if you can use a QTcpSocket across different threads)... and then use the QAbstractSocket::setSocketDescriptor at thread startup...
hth.
Bookmarks