Problem in receiving data on QTcpSocket
I am writting a client application using QTcpSocket, my server has been written using winsock API not using QT.
from my client socket(QTcpSocket) , whatever be data I am sending to server it is received by server correctly, but when server replied I am not getting any data at client. Even I tried to put bytesAvailable() in a while loop also, but I didnt get any data.
Note :- At server side I debugged and checked that winsock API send() has been written the data successfully to sockets.
Please help where I am going wrong.
- In your client application, is the QTcpSocket signal readyRead() emitted when it should receive some data ?
- Try to debug the QTcpSocket signals connected(), disconnected(), error() ! maybe your client is disconnected at the time it should receive some data from the server..
- do you have some source ?
Thanks for your suggestion.
Actually I am writting a dll that will get loaded by mstsc.exe process on client machine.
WHile going through the architecture of qt application I came to know that there should be one QApplication object exist, so that I created one QApplication global object, but didnt call exec on that.
int argc = 0;
QApplication appObject(argc, NULL);
Could it be a reason that since I am not calling exec() on my qapplication object , my socket is not receiving the data. If I will call also , what should be the idle place to call that since after that control will not return from this function, and I am writting dll here not exe.
Is it mandatory to call exec() to even get the signals as well???
Meanwhile I will try to debug the signals and will come back.
That should be the problem!
Qt Signals & Slots rely's on the event-loop,
When you initialize a QApplication (Gui) or QCoreApplication (non-Gui), the event-loop starts after you call exec()!
Now the problem is that a QApplication or QCoreApplication needs to be created in the main thread!
and that thread is started before your library is loaded...
good thing is there are some options! :)
You can can try to call QApplication::processEvents() from your main applications event loop
You can create a second thread and start QApplication::exec() from there