We have an application that performs various requests. It launches up to four threads and launches their allocation.
This part is as follows:
if len(self.threads) == 4:
self.__maxThreadsMsg(base)
return False
else:
self.threads.append(Extractor(self.ui, base))
self.threads[-1].start()
self.__extractionMsg(base)
return True
Our class Extractorinherits QThread:
class Extractor(QThread):
def init(self, ui, base):
QThread.__init__(self)
self.ui = ui
self.base = base
def run(self):
self.run_base(base)
and self.uiset to Ui_MainWindow():
class Cont(QMainWindow):
def __init__(self, parent=None):
QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
There is a specific database that sends data to the user (back to the main window) before continuing (in this case, a pop-up window with two buttons):
msg_box = QMessagebox()
msg_box.setText('Quantity in base: '.format(n))
msg_box.setInformativeText('Would you like to continue?')
msg_box.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
signal = msg_box.exec_()
How can I pause a thread at a specific point, display a window (which, I believe, will return to the main thread) and return to the workflow by sending an event with the click of a button?
I read a little about the signals, but this seems confusing since this is my first time dealing with threads.
: : , :
thread = QThread(self)
worker = Worker()
worker.moveToThread(thread)
worker.bv.connect(self.bv_test)
thread.started.connect(worker.process())
thread.start()
@pyqtSlot(int)
def bv_test(self, n):
k = QMessageBox()
k.setText('Quantity: {}'.format(n))
k.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
ret = k.exec_()
return ret
Worker:
class Worker(QObject):
bv = pyqtSignal(int)
def process(self):
self.bv.emit(99)
, ret , . :
TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'