[PyKDE] error(int) signal from QTcpSocket not firing

Ewald de Wit erdewit at zonnet.nl
Sun Jan 28 11:26:17 GMT 2007


In PyQt4 the error(int) signal from QTcpSocket seems to never fire anymore.
For example, when trying to connect to a non-existing host, nothing
happens after calling connectToHost. In PyQt3 this would result in
an error(int) signal being raised that indicated a 'Connection refused'.

Please see the test script below on how to reproduce this.

-- 
  --  Ewald


import sys
import signal
import PyQt4.Qt as qt
import PyQt4.QtNetwork as qtnetwork


class SocketTest( object ):

    def __init__( self, host, port ):
        self.socket = qtnetwork.QTcpSocket()

        qt.QObject.connect( self.socket, qt.SIGNAL( 'error(int)' ),
                self.onError ) # This is not working anymore.
        qt.QObject.connect( self.socket, qt.SIGNAL( 'connected()' ),
                self.onConnected )
        qt.QObject.connect( self.socket, qt.SIGNAL( 'disconnected()' ),
                self.onDisconnected )

        self.socket.connectToHost( host, port )

    def onError( self, i ):
        print 'onError', self, self.socket.errorString()

    def onDisconnected( self ):
        print 'onDisconnected'

    def onConnected( self ):
        print 'onConnected'


signal.signal( signal.SIGINT, signal.SIG_DFL )
app = qt.QApplication( sys.argv )
test = SocketTest( 'dummyhostname', 80 )
#test = SocketTest( 'localhost', 80 )
app.exec_()




More information about the PyQt mailing list