Unsolved QTcpSocket NetworkError with Wifi OK but Internet NOK
-
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
I hit NetworkError
Could you please share the error? Specially the error string...
-
@Pablo-J-Rogina Hi, here is how I manage errors (I added the error string) :
connect(_client, SIGNAL(error(QAbstractSocket::SocketError)), this SLOT(error(QAbstractSocket::SocketError)));
void myClass::error(QAbstractSocket::SocketError error) { qDebug() << "ERROR " << error; qDebug()<< "Error string "<<_client.errorString(); }
So in the App output I get :
"ERROR QAbstractSocket::NetworkError".
Error string "Host unreachable"I also ran my code in debug mode but I have no additionnal information about the error :/
-
Ok guys, I finally found what causes the problem :
It is in my method connectionWifi() :
void MyClass::connectionWifi() { _connectionAttempts++; qDebug()<<"@@ Connection wifi"; QString resultDisk; QProcess process; int returnCode = process.execute("netsh wlan connect name=wifiAp"); process.start("netsh wlan show networks"); process.waitForFinished(); resultDisk = process.readAllStandardOutput(); if(returnCode==0){ if(resultDisk.contains("wifiAp")){ ui->label_statutWifi->setText(tr("Détecté")); connection(); }else{ ui->label_statutWifi->setText(tr("Non connecté")); ui->label_connect->setText(tr("Outil non détecté")); } }else{ ui->label_statutWifi->setText(tr("Wifi de la tablette éteind")); ui->label_connect->setText(tr("Activez le WiFi")); } }
If I comment this line it works well :
int returnCode = process.execute("netsh wlan connect name=wifiAp");
I don't know why this line makes the code not working when the the ethernet cable is unplugged (the ethernet network has no link with the wifi network I am trying to connect to).
-
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
int returnCode = process.execute("netsh wlan connect name=wifiAp");
Try unplugging ethernet cable and run
netsh wlan connect name=wifiAp
from a Command Prompt. What happens, does it block? -
@JonB It does not block when I run this command, I get the output " the connection request was successful"
-
Then try again in your code but building the parameter list rather than passing the complete command as a string.
I guess there's an issue with the = part.
-
This post is deleted! -
@SGaist Did you mean something like that ? :
QString cmd = "netsh"; QStringList arguments; arguments <<"wlan"<<"connect"<<"name=mScan"; int returnCode = process.execute(cmd, arguments);
It doesn't change the behavior, I have the output "the connection request was successful", it connects my PC to the wifi access point, but if I run this commend the connectToHost method hits NetworkError.
-
-
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
Error string "Host unreachable"
This is a routing issue. You may want to capture and analyze network traffic (i.e. using Wireshark) to see what's going on under your Qt app depending on what connections (wireless or wired) you have on your client PC