0

I have a pyqt5 GUI and there are some functions i want to run in a list. One of the functions is to open a pop window(QDialog)self.openPassDialog but the loading sign on the cursor appears and the program crashes when i click on anthing.

I have used a thread to run the call_va_funcs() function, without the pop up window it works fine but with the pop up window it crashes.

The pop up window should automatically pop up instead of having to use a somebutton.clicked.connect(self.openPassDialog)

can someone show me how it could be done or how to solve this issue please, i am not well versed in programming

This is what I have tried but it gets stuck when the pop up window(QDialogbox) needs to appear

    def openPassDialog(self):
        self.pass_window = QtWidgets.QDialog()
        self.pass_ui = Ui_PassDialog()
        self.pass_ui.setupUi(self.pass_window)
        self.pass_window.show()


def call_va_funcs(self, stop):
        self.disableZüruckVA()
        if self.AFVV == "FW-1.0.0":
            self.f_list = [self.ping_all_va, self.run_rxtx, self.call_netzteil, self.write_parameter, self.openPassDialog, 
            self.run_sf, self.checkbox_ledVA,  self.db_insert_info_va, self.run_reboot]#self.run_reboot
    while True:
            try:
                correct = urllib.request.urlopen("http://192.168.100.2", timeout=10).getcode()
                print(correct, "192.168.100.2 is reachable: FAIL")
                if correct  == 200:
                    self.enableZüruckVA()
                    self.exitflag == True
                    break
                break
                    #### pop up fenster #### switch to 3rd screen
            except Exception:
                for self.funcs in self.f_list:
                    self.funcs()
                    time.sleep(1)
                    if self.exitflag == True:
                        self.enableZüruckVA()
                         #### pop up fenster #### switch to 3rd screen
                        break        
                self.enableZüruckVA()
            break


    def thread_all_funcs_va(self):
        self.exitflag = False
        self.thread_funcs_va = threading.Thread(target=self.call_va_funcs, args =(lambda : self.exitflag,))
        self.thread_funcs_va.start()



Asram
  • 3
  • 2

1 Answers1

0

You should not touch and especially not create any Qt-thingey from a new thread like that, instead you should use signals to communicate between them.

from master thread make new signal and connect it:

signal.whatevername.connect(self.openPassDialog)

make sure the slave thread has the signal and from slave thread run:

signal.whatevername.emit()

and master thread will run the command on the slaves behalf, in this case: self.openPassDialog()

Plutonergy
  • 39
  • 1
  • 3