Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved to 'Mobile and Embedded'] socket->ConnectToHost() making nothing on Android device
Qt 6.11 is out! See what's new in the release blog

[Moved to 'Mobile and Embedded'] socket->ConnectToHost() making nothing on Android device

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.9k 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.
  • E Offline
    E Offline
    Eskay
    wrote on last edited by
    #1

    Hi,

    I'm using Qt 5.2, QtCreator 3.0, Windows8 64 bits
    I've had a look at a lot of forums, but I haven't seen the same problem with QtCreator3.0

    I'm trying to make an application to connect an Android Qt client to Desktop Qt server with WI-FI. Desktop server and android device are connected to the same Wi-Fi network.
    I manage to get the connection when I run both client and server on desktop, but it does not work on when the client runs on Android device.
    I tried on 2 android devices, Samsung Galaxy S3 and Samsumg Galaxy Ace

    The main problem is that I connected "QTcpSocket::connected()" and "QAbstractSocket::SocketError" to my applicaiton, and none of them are called after "connectToHost()" on the android device.

    Concerning permissions, i allowed those ones :
    android.permissions.ACCESS_WIFI_SATE
    android.permissions.CHANGE_WIFI_SATE
    android.permissions.INTERNET
    android.permissions.WRITE_EXTERNAL_STORAGE

    my project .pro file contains
    QT += network

    I can see logs of the "connecter" function above, but nothing neither from connected, nor from SocketError

    Here are some parts of my code

    Socket Creation :
    @
    //client
    socket = new QTcpSocket();
    connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(socket, SIGNAL(connected()), this, SLOT(connecte()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));
    @

    Connect function :
    @
    void NetworkClient::connecter(QString p_ip,QString p_port)
    {
    qDebug() << "connexion : " << p_ip << " / "<< p_port;
    socket->abort();
    socket->connectToHost(p_ip, p_port.toUInt());
    }
    @

    Error function
    @
    void NetworkClient::erreurSocket(QAbstractSocket::SocketError erreur)
    {
    switch(erreur) // On affiche un message différent selon l'erreur qu'on nous indique
    {
    case QAbstractSocket::HostNotFoundError:
    _qmlCpp->invokeQmlFunction("log","ERREUR : le serveur n'a pas pu être trouvé. Vérifiez l'IP et le port.");
    //listeMessages->append(tr("<em>ERREUR : le serveur n'a pas pu être trouvé. Vérifiez l'IP et le port.</em>"));
    break;
    case QAbstractSocket::ConnectionRefusedError:
    _qmlCpp->invokeQmlFunction("log","ERREUR : le serveur a refusé la connexion. Vérifiez si le programme "serveur" a bien été lancé. Vérifiez aussi l'IP et le port");
    //listeMessages->append(tr("<em>ERREUR : le serveur a refusé la connexion. Vérifiez si le programme "serveur" a bien été lancé. Vérifiez aussi l'IP et le port.</em>"));
    break;
    case QAbstractSocket::RemoteHostClosedError:
    _qmlCpp->invokeQmlFunction("log","ERREUR : le serveur a coupé la connexion.");
    //listeMessages->append(tr("<em>ERREUR : le serveur a coupé la connexion.</em>"));
    break;
    default:
    _qmlCpp->invokeQmlFunction("log","ERREUR : erreur.");
    //listeMessages->append(tr("<em>ERREUR : ") + socket->errorString() + tr("</em>"));
    break;
    }

    }
    @

    Connected :
    @
    void NetworkClient::connecte()
    {
    _qmlCpp->invokeQmlFunction("connectionOk","Connection OK");
    }
    @

    I saw a post with a similar problem to mine, but the person forgot to include QtNetwork library in the package configuration. In my case, I think there is not such problems, as far as I'm using QtCreator3.0 (that apparently includes automatically libraries).

    Thank you for helping.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eskay
      wrote on last edited by
      #2

      Hi,

      No one has any idea of what the problem could be ?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBoosalis
        wrote on last edited by
        #3

        Don't know much about building a package on Android, but do you not have to specify in its manifest file what permsions the app wants to use. I would think networking would be something you have to specify as it would alert the installer that this app might be sending data out.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eskay
          wrote on last edited by
          #4

          Thank you for responding.

          In fact, this permissions were set in the manifest :

          bq. Concerning permissions, i allowed those ones :
          android.permissions.ACCESS_WIFI_SATE
          android.permissions.CHANGE_WIFI_SATE
          android.permissions.INTERNET
          android.permissions.WRITE_EXTERNAL_STORAGE

          And apparently "INTERNET" was the only one needed, I tried with "ACCESS_WIFI_STATE", and "CHANGE_WIFI_STATE" to see if this was getting better, unfortunately without success

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ankursaxena
            wrote on last edited by
            #5

            U can put it in another group related to android. May be u get proper response there.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Eskay
              wrote on last edited by
              #6

              You are right...
              I saw some responses concerning android in this group, so I beleived this was the good place to post.

              I Moved it to "Mobile and Embedded":https://qt-project.org/forums/viewthread/38851/

              1 Reply Last reply
              0

              • Login

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