0

Like I said in the hedding, my programm crashes sometimes when I start the following thread. I don't get any Error, It just closes sometimes... If it crashes, then it crashes in the first round of the while-loop. I think its because of the time.sleep(0.5) because everything before this line works perfectly fine. My complete Programm runs perfectly fine, its just this part here which gives me a headache:

    def TimeClock(self):
        time.sleep(5)
        TimeThreadRunning = True
        Datum = datetime.now()
        self.ui.label_3.setText(Datum.strftime("%H : %M"))
        while TimeThreadRunning == True:
            print("Uhrzeit wird überprüft")
            time.sleep(0.5)
            Datum = datetime.now()
            self.ui.label.setText(_translate("GUI", Datum.strftime("%d.%m.%Y")))
            self.ui.label_2.setText(_translate("GUI", Datum.strftime("%H : %M")))

    TimeTread = threading.Thread(target=TimeClock, args=(self,))
    TimeTread.daemon = True
    TimeTread.start()

Hope somebody can help. Greetingsfrom Germany

Flo Lell
  • 1
  • 1
  • try this `TimeTread = threading.Thread(target=TimeClock, args=(self,)) TimeTread.start()` – Ayaz Khan Feb 15 '22 at 17:03
  • Qt does not support GUI operations of any kind outside the main thread. Use a QThread instead, and send updates to the main thread via signals (which are thread-safe). – ekhumoro Feb 15 '22 at 17:34
  • Thanks for the feedback. I'll try if that works – Flo Lell Feb 15 '22 at 19:21

0 Answers0