Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Code Refactoring for Signals and Slots

Code Refactoring for Signals and Slots

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 617 Views 1 Watching
  • 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
    pylix
    wrote on last edited by
    #1

    Hello,

    I have writing a UI using pyside. Problem is I have around 15 buttons in my application that when pushed open a dialog box and ask for a file or directory and then update a related lineEdit.

    I have a askforfile() method which I like to associate with all these buttons. Unfortunately using the clicked.connect way of handling slots in PySide I have to write a new function for each button that would actually do the same thing.

    So I tried to use lamba function in order to be able to pass the name of the lineEdit as a parameter of the askforfile() method. but I am getting error implementing this.
    Could anybody please help me figure out what I am doing wrong ?

    @class MainAppWindow(QMainWindow):

    def __init__(self, 
                 parent=None):
        super(MainAppWindow, self).__init__()
       
        self.ui = Ui_MainWindow.Ui_MainWindow()
        self.ui.setupUi(self)    
        self.ui.X_Vel_pushButton.clicked.connect(lambda name="X_Vel_lineEdit": self.askforfile(name))
        def askforfile(self,currentLineEdit):
        
             curFileName=self.ui.currentLineEdit.text()
            (fileName, _selectedFilter) = QtGui.QFileDialog.getOpenFileName(self, filter="*.txt;;*.*",viewMode="Detail")
            if fileName!="" and fileName!=curFileName:
                 self.ui.X_Vel_lineEdit.setText(fileName)
    

    @
    I am guessting something is wrong in my passing of currentLineEdit to askforfile().
    I would appreciate any help.

    Thanks in advance

    1 Reply Last reply
    0

    • Login

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