A
A
Alexey162021-10-08 16:52:48
PyQt
Alexey16, 2021-10-08 16:52:48

How to establish interaction between time.sleep and close?

The checkupdate function works in a thread and checks for updates, if there are no updates, the text "Checking for updates ..." should be replaced with "No updates. Starting", wait a while for the user to see this, then the current window closes and the main one opens

. in fact, the text does not change, and after the sleep time passes, the program closes, the text does not change

. I understand that you can simply refuse this, but I would like to know why this happens

Code fragment:

class Worker(QObject):
    bool_signal = pyqtSignal(bool)

    def __init__(self):
        super().__init__()

    @pyqtSlot()
    def checkUpdate(self):

        # code

        if current_version:
            self.bool_signal.emit(True)
        else:
            self.bool_signal.emit(False)

class SplashScreen(QMainWindow, SetupWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.main = MainWindow()
        self.setupUi(self)

        #code

        self.thread = QThread()
        self.worker = Worker()
        self.worker.moveToThread(self.thread)
        self.worker.bool_signal.connect(self.after_search_update)
        self.thread.started.connect(self.worker.checkUpdate)
        self.thread.start()
        self.show()


    def after_search_update(self, boolean: bool):
        if boolean:
            self.Status_text.setText("Обновлений нет. Запуск")
            # QtCore.QThread.sleep(2) пробовал использовать такой вариант
            time.sleep(2)
            self.close()
            self.main.show()
        else:
            pass

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question