0

I am trying to open a child window in my QT application. When I call it from the UI thread it works fine but when I call QtWidgets.QMainWindow().show() from threading.Timer function, the whole application freezes.

This is my Main Window

def main():
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())

Timer function

def checkForAlarm(self):
    if self.getIsActive() :
        if self.handler != None:
            timeDelta = self.getTimeLeft()
            if timeDelta.total_seconds()<1 and timeDelta.total_seconds()>-1 :

                self.handler(self) # calls raiseAlarm to open child window

        Timer(1.0, self.checkForAlarm).start()

This is the call from my function called from a thread.

def raiseAlarm(self,alarm:Alarm):
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_AlarmDialog()
    ui.setupUi(MainWindow)

    MainWindow.show() #Application becomes unresponsive

What is the solution for this?

Taufiq Abdur Rahman
  • 1,246
  • 4
  • 24
  • 42

0 Answers0