0

I'm trying to send variables from a dialog back to the Main Window. However, so far I have only been able to pass the default values. My code looks like this:

class OptionsDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Advanced_Options()
        self.ui.setupUi(self)
        self.ui.buttonbox_options.accepted.connect(self.Get_Data) 

    def Get_Data(self):
        self.value = self.ui.sellingSpin.value()
        return self.value

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, *args, obj=None, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        """data about MainWindow"""

    def get_input_data(self):
        Options = OptionsDialog(self)
        self.value = Options.Get_Data()
        print(self.value) # this is just an example to see what variable I got

In the dialog I count with many spinboxes. Since the default value is 1, I always get 1. No matter if I had changed it before or not.

David
  • 1
  • Insert `Options.exec()` in the second line, *before* `self.value = Options.Get_Data()`. Also, only classes and constants should have capitalized name. – musicamante Dec 20 '21 at 13:24
  • 1
    A **new** dialog will be created every time `get_input_data` is called. If you want to keep the previous values, you must reuse *the same dialog*. So in `MainWindow.__init__`, add the line `self.options = OptionsDialog(self)`. Then in `get_input_data`, replace the first line with `self.options.exec()`. You can then do `print(self.options.ui.sellingSpin.value())` to show the current value. There's no need to store the value as `self.value`, because you can always get it directly from the dialog itself. – ekhumoro Dec 20 '21 at 14:38

0 Answers0