PyQt lineEdit on textEdited 信号值在函数调用后丢失

PyQt lineEdit on textEdited signal value lost after function call

#^^^^class stuff here for setting UI^^^^


# connecting combobox to slot/function get_baffle_number
   self.baffle_number_combobox.currentIndexChanged.connect(get_baffle_number)

# connecting PushButton action "clicked" to function on_click
   self.pushButton.clicked.connect(on_click)


#connecting lineEdit to slot/function get_baffle_cost
   self.baffle_cost_lineEdit.textEdited.connect(get_baffle_cost)


@pyqtSlot()
def get_baffle_cost(text):
    baffle_cost = text
    return baffle_cost


def get_baffle_number(text):
    #add 1 to the index returned by comboBox to get the number desired by user
    baffle_number = text + 1
    return baffle_number


def calc_baffle_cost():
    test_total = (get_baffle_cost() * get_baffle_number())
    return test_total


@pyqtSlot()
def on_click(self):
    baffle_cost = calc_baffle_cost()
    print(baffle_cost)

在我通过 pyqtSlot()lineEdit 连接到该函数后,它似乎获得了值,但如果我尝试从另一个函数使用 baffle_cost,它会立即转储它。我在调试期间在 PyCharm 中观看它,只要 lineEdit 看起来有焦点,它就会保持它。当pushButton失去价值时按pushButton是对的。

我无法在 get_baffle_cost.

的任何地方使用返回的 baffle_cost

我错过了什么吗?我得到的最远的是尝试简单地打印 calc_baffle_cost() 并打印一个十六进制。我假设这是一个内存位置,但不能确定。 (Python 的新手)

抱歉,如果这还不够信息。我只是试图从 lineEdit 中获取 baffle_cost 并将其乘以从 comboBox.

中获取的值

看来我的问题有两方面,甚至更多。

我没有正确确定我的函数范围,也没有使用正确的命名空间。 (抱歉,如果这个术语不正确。我是 Python 和 PyQt 的新手。)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

    # sizing of widgets

    def retranslateUi(self, MainWindow):

    # UI stuff here QlineEdits, etc.
    self.baffle_cost_lineEdit.editingFinished.connect(self.get_baffle_cost)

    def get_baffle_cost(self):
        baffle_cost = self.baffle_cost_lineEdit.text()
        return baffle_cost

这需要与我的 Ui_MainWindow Class 中的 retranslateUi() 函数处于相同的范围(缩进),如上。

我想如果我能更好地构建我的项目,这就不是问题了。我肯定已经吸取了关于将所有内容都放在一个脚本中的教训。 (program.py)

我遇到的另一个问题是 PyQt 函数 text()QlineEdit returns 和 QString 而不是 str 调用.我只需要将它转换为一个字符串。

我丢失了值,因为函数 get_baffle_cost 的范围不正确 baffle_cost_lineEdit