prashant
1st December 2009, 10:06
Related to : PyQt 4.6.1
This is regarding a simple socket reading in my application.
I am using QAbstractSocket.UdpSocket for the purpose.
Once the socket is connected to given host and port, it should constantly watch for data.
Question 1:
Do I have to use a thread to watch socket for data being available or signal "readyRead" will
do this job?
Question 2:
Code for sending data on socket:
socket = QtNetwork.QAbstractSocket(QtNetwork.QAbstractSocke t.UdpSocket, self)
socket.connectToHost(host, port)
socket.writeData("This is the test string.")
socket.disconnectFromHost()
socket.close()
The line:
socket.writeData("This is the test string.")
is crashing the application. why?
Question 3:
What's the proper way to close a socket?
I am using:
self.socket.disconnectFromHost()
self.socket.waitForDisconnected()
self.socket.close()
When I am closing the socket using above code, no error or warning is produced, but when I close the dialog box where I am implementing my tests, message is printed to stdout:
QWaitCondition: Destroyed while threads are still waiting
Please be patient, I have a limited knowledge on threads and sockets.
This is regarding a simple socket reading in my application.
I am using QAbstractSocket.UdpSocket for the purpose.
Once the socket is connected to given host and port, it should constantly watch for data.
Question 1:
Do I have to use a thread to watch socket for data being available or signal "readyRead" will
do this job?
Question 2:
Code for sending data on socket:
socket = QtNetwork.QAbstractSocket(QtNetwork.QAbstractSocke t.UdpSocket, self)
socket.connectToHost(host, port)
socket.writeData("This is the test string.")
socket.disconnectFromHost()
socket.close()
The line:
socket.writeData("This is the test string.")
is crashing the application. why?
Question 3:
What's the proper way to close a socket?
I am using:
self.socket.disconnectFromHost()
self.socket.waitForDisconnected()
self.socket.close()
When I am closing the socket using above code, no error or warning is produced, but when I close the dialog box where I am implementing my tests, message is printed to stdout:
QWaitCondition: Destroyed while threads are still waiting
Please be patient, I have a limited knowledge on threads and sockets.