Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code works for me (Python 2.6 here). I removed the inheritance of <code>CountT</code> with <code>imiserv</code> and replaced the ui object by <del>the QLabel <code>S_label</code></del> the <code>imiserv</code> instance instead. A <code>pyqtsignal</code> allows the thread CounT to write text to the QLabel and the QTextEdit:</p> <pre><code>import socket import threading from PyQt4 import QtCore, QtGui from imigui import Ui_MainWindow class imiserv(QtGui.QMainWindow): send_msg = pyqtSignal('QString', 'QString') def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.Sport_lineEdit.setMaxLength(5) self.ui.Sconnect_pushButton.clicked.connect(self.serv) self.send_msg.connect(self.my_slot) def write_msg(self, lbl_msg, txt_msg): self.ui.S_label.setText(lbl_msg) self.ui.Clog_textEdit.setText(txt_msg) def serv(self): self.sersock= socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sersock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.host= str(self.ui.Sip_lineEdit.text()) self.port= int(self.ui.Sport_lineEdit.text()) MY_LOCK = threading.Lock() class CountT(threading.Thread): def __init__(self, parent): threading.Thread.__init__(self) self._parent= parent def run(self): MY_LOCK.acquire() self._parent.send_msg.emit("Waiting connections","") while True: cliconn, (addr, remoport)= self.__parent.sersock.accept() self.cstr= cliconn.recv(1024) self._parent.send_msg.emit("{0}:{1} is connected.".format(addr, remoport), self.cstr) cliconn.close() MY_LOCK.release() try : self.sersock.bind((self.host, self.port)) self.sersock.listen(5) a= CountT(self) a.daemon= True # for exit from thread when close gui a.start() except socket.error as err: self.ui.S_label.setText(err.strerror.decode("utf-8")) self.ui.Clog_textEdit.setText(err.strerror.decode("utf-8")) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) s = imiserv() s.show() sys.exit(app.exec_()) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload