Android QtNetwork

  • I have a software compiled for Windows and Android. Both are working ok. When i attached the QtNetwork to use QUdpSocket in windows is working ( it asks me for allow to port to open) and it is working fine. When i use it for android , android is not receiving data. What can i do ? This is my code

    @ udpSocket->bind(QHostAddress(""),5000);
    QHostAddress sender;
    quint16 senderPort;
    bytesReaded = this->udpSocket->readDatagram((char*)buffer,bufferLength,&sender, &senderPort);
    this ip is the ip of android phone

  • Moderators

    did you set the Android permissions of your app correctly?

  • how can i set the permissions ?

  • Moderators

  • I tested that and not work. I have the same problem on linux also... the network is not working. I am running Linux version on VMWare machine but i don't think that's a problem..

  • Moderators


    I have my following code which guaranteed works on my phone but i'm not binding it to any particular address.

    udpSocket = new QUdpSocket(this);
    udpSocket->bind(15687, QUdpSocket::ShareAddress);
    connect(udpSocket, SIGNAL(readyRead()),
    this, SLOT(processPendingDatagrams()));

    void Sync::processPendingDatagrams()
    QString stmp;
    while (udpSocket->hasPendingDatagrams()) {
    QByteArray datagram;
    udpSocket->readDatagram(, datagram.size());
    stmp = QString(;

    You can try to add the joinMulticastGroup and see if above works.

    Edit: I've also set android.permission.INTERNET permission

  • Everything i enter a get the message :
    I remember in windows it was working ok!

  • Moderators

    Ok, now from OS point of view.
    Is multicasting enabled on your machine ? use ifconfig command on your linux machine.
    Eg. if interface is eth0
    @ifconfig eth0@

    If it contains MULTICAST then it is enabled,
    or Paste the output here

  • Guys i found the solution but i don't know the reason qt is acting like that in linux

    First Source code i use :

    As you can see i have added AnyIPv4.
    Why that's happened ?
    When do we use AnyIPv4?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.