Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android QtNetwork
Qt 6.11 is out! See what's new in the release blog

Android QtNetwork

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 5.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clouca
    wrote on last edited by
    #1

    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("192.168.1.15"),5000);
    udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
    QHostAddress sender;
    quint16 senderPort;
    bytesReaded = this->udpSocket->readDatagram((char*)buffer,bufferLength,&sender, &senderPort);
    @
    this ip is the ip of android phone 192.168.1.15

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      did you set the Android permissions of your app correctly?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        clouca
        wrote on last edited by
        #3

        how can i set the permissions ?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          You need to edit your manifest file.
          read "this":http://doc-snapshot.qt-project.org/qtcreator-2.8/creator-deploying-android.html#editing-manifest-files and "this":http://developer.android.com/reference/android/Manifest.permission.html.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • C Offline
            C Offline
            clouca
            wrote on last edited by
            #5

            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..

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Hi,

              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;
              datagram.resize(udpSocket->pendingDatagramSize());
              udpSocket->readDatagram(datagram.data(), datagram.size());
              stmp = QString(datagram.data());
              }
              @

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

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

              157

              1 Reply Last reply
              1
              • C Offline
                C Offline
                clouca
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  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

                  157

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    clouca
                    wrote on last edited by
                    #9

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

                    First Source code i use :
                    @
                    udpSocket->bind(QHostAddress("192.168.1.15"),5000);
                    udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
                    @

                    Fix
                    @
                    udpSocket->bind(QHostAddress("192.168.1.15").AnyIPv4,5000);
                    udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
                    @
                    As you can see i have added AnyIPv4.
                    Why that's happened ?
                    When do we use AnyIPv4?

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved