Isn’t that what PyQt’s signal-slot mechanism does? The input box you want to input, such as LineEdit, corresponds to a slot. A signal is sent to the processing place, and PyQt does the binding itself without any specific function calls. , the code looks much cleaner In the example below, BackendThread simulates the background thread. After the data is processed, it is updated to the foreground and refreshed every second. Just replace it with your own logic
# -*- coding: utf-8 -*-
from PyQt4.Qt import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time
class Backend(QThread):
update_date = pyqtSignal(QString)
def run(self):
while True:
data = QDateTime.currentDateTime()
self.update_date.emit(QString(str(data)))
time.sleep(1)
class Window(QDialog):
def __init__(self):
QDialog.__init__(self)
self.resize(400, 100)
self.input = QLineEdit(self)
self.input.resize(400, 100)
def handleDisplay(self, data):
self.input.setText(data)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
b = Backend()
w = Window()
b.update_date.connect(w.handleDisplay)
b.start()
w.show()
app.exec_()
Define a global variable and write the current line number into the variable when reading The scheduled program regularly updates the value on the interface (take the global variable)
This is the simplest and crudest way
Another one, execute asynchronously when reading, directly update the number of rows to the interface
Isn’t that what PyQt’s signal-slot mechanism does? The input box you want to input, such as LineEdit, corresponds to a slot. A signal is sent to the processing place, and PyQt does the binding itself without any specific function calls. , the code looks much cleaner
In the example below, BackendThread simulates the background thread. After the data is processed, it is updated to the foreground and refreshed every second. Just replace it with your own logic
Define a global variable and write the current line number into the variable when reading
The scheduled program regularly updates the value on the interface (take the global variable)
This is the simplest and crudest way
Another one, execute asynchronously when reading, directly update the number of rows to the interface