[SOLVED] Android QT5.2 : 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,
I have nearly the same problem with QT5.4.1. But it does not work for me.
Here is my code: https://git.hoffmann-projects.de/?p=ds-qrpigpiocontrol.git;a=summaryCan you help me?
Thanks!
(I use: Linux (64bit), QT5.4.1, qtcreator3)
-
Hi,
I have nearly the same problem with QT5.4.1. But it does not work for me.
Here is my code: https://git.hoffmann-projects.de/?p=ds-qrpigpiocontrol.git;a=summaryCan you help me?
Thanks!
(I use: Linux (64bit), QT5.4.1, qtcreator3)