Unsolved Call a function value from another python file - APP crashes
-
Hi, I am trying to get a value from a function that is in another python file. Whenever I try to get the value app crashes. I have attached the code for reference.
class Ui_MainWindow(QObject): def setupUi(self, MainWindow): .................................UI code ............................. self.casesecondbutton.clicked.connect(self.casesecondbutton_click) @pyqtSlot( ) def casesecondbutton_click(self): casesecondlabel = self.casesecondline.toPlainText() print(casesecondlabel) return casesecondlabel
I have two buttons. One is for storing a value in a variable. Another b utton is for getting the stored value. I am using two buttons since I need to perform some other operations.
In this MyApp.py file. I am calling the function value. It is crashing.
from mainwindow import Ui_MainWindow class MainWindowUIClass( Ui_MainWindow ): def __init__( self ): super().__init__() def loadfromdbbutton_click(self): name = Ui_MainWindow.casesecondbutton_click() print(name)
For clear understanding. I have a textedit where I can enter a value. After entering and pressing casesecondbutton the value gets stores in casesecondlabel. After pressing loadfrombutton it should get the value for me. I need to use it in for upcoming codes.
-
@praneshpk
Do you even callUi_MainWindow
'ssetupUi()
? Isself.casesecondbutton
already set up as a button at the time you callname = Ui_MainWindow.casesecondbutton_click()
? [I'm not sure in Python thatUi_MainWindow.casesecondbutton_click()
is correct, does it make any difference if you goself.casesecondbutton_click()
?] Run your code in a debugger and discover exactly which line it is on when it "crashes".I don't know what you are trying to do here, but I'm afraid the code is all wrong. Slots do not return values. You do not want to call
casesecondbutton_click()
explicitly fromloadfromdbbutton_click()
. I don't know why you have a separateMainWindowUIClass
fromUi_MainWindow
.