[Moved to 'Mobile and Embedded'] socket->ConnectToHost() making nothing on Android device
-
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.0I'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 AceThe 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_STORAGEmy project .pro file contains
QT += networkI 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.
-
Hi,
No one has any idea of what the problem could be ?
-
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.
-
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_STORAGEAnd 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
-
U can put it in another group related to android. May be u get proper response there.
-
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/