0

I cannot figure out, how I'm able to get variable (dictionary) out from the class.

When the button "ETSI" is clicked, the code will get all inputs from the GUI window (type fields and checkboxes) that the user provided and creates a dictionary out of that data.

The problem is that I cannot figure out how to return that dictionary, from the class.

CODE:

    from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
    from PyQt5 import uic
    import sys
    
    class UI(QWidget):
        def __init__(self):
            super().__init__()
    
            # --- Init window ------#
            uic.loadUi("DesignerWindow/window.ui", self)
    
            # --- Button action ------#
            button = self.findChild(QPushButton, 'etsiButton')
            # ---- Define action for the button ---#
            button.clicked.connect(self.clicked_btn)
    
        def clicked_btn(self):
            resultList = {}
    
            # Sijainti
            sijaintiInput = self.sijaintiInput.text()
            if sijaintiInput != "":
                resultList ["sijainti"] = sijaintiInput
    
            # Hinta
            hintaInputMin = self.hintaInputMin.text()
            if hintaInputMin != "":
                resultList ["hintaMin"] = hintaInputMin
    
            hintaInputMax = self.hintaInputMax.text()
            if hintaInputMax != "":
                resultList ["hintaMax"] = hintaInputMax
            
            # Asuintilojen pinta-ala
            atpInputMin = self.atpInputMin.text()
            if atpInputMin != "":
                resultList ["atpMin"] = atpInputMin
    
            return resultList
    
    # Execute
    app = QApplication([])
    window = UI()
    window.show()
    sys.exit(app.exec_())
    
    
Antti
  • 89
  • 1
  • 5
  • Also [What effect will exist when using any 'return' statement inside Qt's slot](https://stackoverflow.com/questions/54897668/what-effect-will-exist-when-using-any-return-statement-inside-qts-slot). And don't forget to read [the official signals and slots documentation](https://doc.qt.io/qt-5/signalsandslots.html). – musicamante Jul 21 '21 at 11:52
  • Briefly: signals are not intended as things that can "receive a returned value". Can you clarify what do you need that dictionary for? – musicamante Jul 21 '21 at 11:54
  • @musicamante I need it for the further use of robot framework. Robot framework would take that list and do the automation with that list. – Antti Jul 21 '21 at 12:19
  • it depends on what you mean by "further use". If you need to store that data, then make it an instance member (`self.resultList = {}`). As said, signals do *not* expect any return value, because that's not their purpose and they are not intended to be used like that (nor they should!). – musicamante Jul 21 '21 at 13:05

0 Answers0