[PyQt] QtNetwork newbie question

David Boddie david at boddie.org.uk
Mon Mar 19 21:00:08 GMT 2012


On Mon Mar 19 19:22:09 GMT 2012, John Stewart wrote:

> So my first thought was to try not binding the nextPendingConnection()
> which looks like this:
>
> self.connect(self.tcpServer.nextPendingConnection(),
> QtCore.SIGNAL("readyRead()"), self.tcpSocketReadyReadEmitted)

OK, this looks fine, I think.

> But then how do access the readAll() for the data thats being sent?  Doing
> the same bit on the tcpSocketReadyReadEmitted function throws an
> AttributeError.
>
> def tcpSocketReadyReadEmitted(self):
>         data = str( self.tcpServer.nextPendingConnection().readAll() )
>         print data
>
> returns
>
> AttributeError: 'NoneType' objet has no attribute 'readAll'

In the tcpSocketReadyReadEmitted() method, you need to call self.sender() to
get the socket object that emitted the signal. If you call the
nextPendingConnection() method again, you may get a different socket object
or None.

It seems that the library removes connections from an internal queue when
you call nextPendingConnection(), so don't call it again until you have
handled the existing connection.

> Again, total beginner at this so sorry if the answer is glaring.

No problem. It's better to ask questions when you're still a beginner!

David


More information about the PyQt mailing list