Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Call a function value from another python file - APP crashes
Forum Updated to NodeBB v4.3 + New Features

Call a function value from another python file - APP crashes

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 244 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    praneshpk
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • P praneshpk

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved