Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.

    mainwindow.py

    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
    

    MyApp.py

    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 call Ui_MainWindow's setupUi()? Is self.casesecondbutton already set up as a button at the time you call name = Ui_MainWindow.casesecondbutton_click()? [I'm not sure in Python that Ui_MainWindow.casesecondbutton_click() is correct, does it make any difference if you go self.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 from loadfromdbbutton_click(). I don't know why you have a separate MainWindowUIClass from Ui_MainWindow.


Log in to reply