Solved QT android application suddenly disconnect.
-
Hi guys,
I am developing C++ qt application that is meant to be multi platform. (Windows, Linux, Android, IOS)
On the windows and linux i do not have problems, but on the android there is a problem with the connection.
Application is based on client server communication. And when its working on Android device, it is attached to the server via WiFi.
The problem is: After running for few hours, sometimes more, sometimes less, application simply disconnect from the server.
Communication is based on the UDP protocol. I am pretty sure that problem is up to the application, because when i try to reproduce problem with turning off wifi on one or another side (client or server) i got completely other log messages.So basically it is like application decide in one moment just to shutdown connection with server. Time for the reproducing bug is always different, sometimes one hour, sometimes ~20hours.
I also compiled application for ios, and on the Ipad, application was working for ~60hours without disconnection.
I still do not have much experience with the QT and now i am stuck, i dont know what to do. Can anyone help me please?
Kind regards,
Stasa
-
@Stasa-Sekulic
Hi and welcome to devnet forum
Do you get an error message/code at all?
Or does it simply disconnect?
Where do you test Android?
Is it an Android phone?Possibly it has something to do with power saving modes on Android or similar things.
-
No, i did not get error message.
I have found that it is somehow (still investigating) to the QTcpSocket and disconnected signal, it disconnect because of that, but still i cannot figure out why it happens and how to fix that.
QTcpSocket *rc_tcpSocket;
connect(rc_tcpSocket, SIGNAL(disconnected()), this, SLOT(rc_disconnected()) );
But for some reason this issue never appears on the IOS device.
I am using Asus Nexus 7 tablet. And i looked for the settings for power save, and turned them off.
-
@Stasa-Sekulic
I would expect that this is simply an issue with the Android device, but not a specific issue of Qt on Android.
However, you are writing in your first post about UDP, but your are using QTcpSocket in your second. What are you using?
-
I came to this thread because I googled the same issue. It is an Anroid-only issue for me (I develop for Android and for iOS). For iOS it stays connected, even overnight. But for Android, maybe 15 to 30 seconds and then, "biz.mycompany.myapp died" in the Application Output window. (Nothing informative in the logcat.)
-
@koahnig @jjdd
Sorry for no update earlier, i have some other issues to solve in parallel.
About UDP and TCP:-
Application can connect to the server via LAN and via WLAN
-
For WLAN it uses TCP
-
For LAN it uses UDP
I have performed again test with more logs, and found that the problem is in THIS LINE
rc_tcpSocket->waitForConnected(1500)
after some ,random ,time this is where i get error and client disconnect from the server.My opinion that issue is code and device related, but i cannot tell for sure, after i read about QTcpSocket i hope i will find what is causing the issue.
-
-
Hi guys,
Can someone explain me with a little more details what does this means?
, and what is meant by using the event loop and connected() signal?
I searched everywhere, and wherever I find QT issue with QAbstractSocket, there is so much answers and solutions. And pretty much every solution is kind a workaround.Kind regards,
Staša
-
@Stasa-Sekulic
The event loop is required for signal-slot mechanism which is summarized here
-
I have found solution after some time. Sorry for late update.
Problem was that when connected() signal was fired, my application was stuck in for loop, and ignored signal. So the problem was design of the application.
-
@Stasa-Sekulic said in QT android application suddenly disconnect.:
I have found solution after some time. Sorry for late update.
Problem was that when connected() signal was fired, my application was stuck in for loop, and ignored signal. So the problem was design of the application.
Glad that you have found the solution for your problem.
Thanks for reporting back