[PyQt] Qthread segmentation fault
lucaberto at libero.it
lucaberto at libero.it
Tue Dec 9 13:19:18 GMT 2008
Hello i get segmentation fault from a small client for connect to irc server here is a part of the code:
class Form(QWidget, Ui_Form):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
super(Form, self). __init__(parent)
self.socket = QtNetwork.QTcpSocket()
self.connect(self.socket, QtCore.SIGNAL("connected()"),
self.connessione)
self.connect(self.socket, QtCore.SIGNAL("readyRead()"),
self.leggo_risposta)
self.connect(self.socket, QtCore.SIGNAL("disconnected"),
self.sconnesso)
self.connect(self.socket, QtCore.SIGNAL("error
(Qtcore.QAbsatctSocket::SocketError)"), self.server_errore)
self.lu = Luca()
self.sock = QtNetwork.QTcpSocket()
self.connect(self.sock, QtCore.SIGNAL("connected()"),
self.conn_sock_due)
self.connect(self.sock, QtCore.SIGNAL("readyRead()"),
self.inizio)
self.connect(self.sock, QtCore.SIGNAL("disconnected"),
self.sconnesso)
self.connect(self.sock, QtCore.SIGNAL("error
(Qtcore.QAbsatctSocket::SocketError)"), self.server_errore)
----------------------------------------------
This part must run because is user for the pong reply to the ping server:
def leggo_risposta(self):
while self.socket.bytesAvailable()>0:
cosa_leggo = self.socket.readData
(self.socket.bytesAvailable())
self.textEdit.append(cosa_leggo)
if 'PING' in str(cosa_leggo):
if len(str(cosa_leggo)) < 20:
frase_pong = ('PONG :' + cosa_leggo[6:-2]+'\n')
self.textEdit.append(frase_pong)
self.socket.writeData(frase_pong)
app.processEvents()
else:
frase_pong = ('PONG :' + cosa_leggo[6:28]+'\n')
self.textEdit.append(frase_pong)
self.socket.writeData(frase_pong)
app.processEvents()
def inizio(self):
self.lu.start()
------------------------------------------------------------------------------------
here the thread start for the download of the file,
class Luca(QtCore.QThread):
def __init__(self, parent=None):
super(Luca, self).__init__(parent)
self.lunghezza = ''
self.sock = ''
self.salvataggio = ''
def run(self):
l_fil = self.salvataggio.tell()
while l_fil < (self.lunghezza):
if self.sock.bytesAvailable()>0:
dati = self.sock.readData(self.sock.bytesAvailable())
self.salvataggio.write(dati)
l_fil = self.salvataggio.tell()
This is only a part of the code.
Regards
Luca
More information about the PyQt
mailing list