QTcpSocket cannot bind to correct IP address

I am creating a Qt5 / C ++ linux application that runs on a multi-NIC system (multihomed). I need to force my outgoing TCP connection to use a specific NIC / IP. I tried the following code, but netstat confirms that my application is still using the wrong local network adapter.

if (m_tcpSocket->bind(localaddress)) qDebug() << "Bind success";


Am I calling it wrong? I see "bind success", so I assume the call is correct ... but I cannot explain why its not working

Update: I found this bug report: https://bugreports.qt.io/browse/QTBUG-29732

Is there a workaround? I can see setLocalAddress () in QAbstractSocket, but I'm not sure if it is the same


source to share

1 answer

I have confirmed that the cause is a bug in the Qt library, reported here . This bug has existed since Qt 4.8 and today we are in Qt 5.3. It's hard to believe that such a significant bug has not been fixed (meaningful for any application using the network)



All Articles