I wrote this code to connect to the ip address of my own machine. bind returns true, though connect wouldn't prompt anything. I also run another program, using same ip and port but these two do not connect.

Qt Code:
  1. void UDP::UDPtInit()
  2. {
  3. socketPort = PORT;
  4. udpsocket = new QUdpSocket(this);
  5. if(!udpsocket->bind(QHostAddress("192.168.111.1"),socketPort))
  6. {
  7. qDebug() << "true";
  8. }
  9. else
  10. {
  11. qDebug() << "false";
  12. }
  13. connect(udpsocket,SIGNAL(readyRead()),this,SLOT(readState()));
  14.  
  15. connect(udpsocket,SIGNAL(connected()),this,SLOT(socketConnected()));
  16.  
  17. connect(udpsocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(socketError(QAbstractSocket::SocketError)));
  18.  
  19. emit clientActive(true);
  20. }
  21.  
  22.  
  23. void UDP::socketError( QAbstractSocket::SocketError )
  24. {
  25. qDebug() << "UDPCLIENT ERROR: "<< udpsocket->errorString();
  26. }
  27.  
  28.  
  29. void UDP::socketConnected()
  30. {
  31. qDebug() << "UDPCLIENT : Socket connected!";
  32. emit clientLogMessage(QString("UDPCLIENT : Connected !"));
  33. }
To copy to clipboard, switch view to plain text mode