1

can I use a return statement from a slot function to provide input to a different 'lambda'd' slot?

something along the lines of the following which I know does not work - as X and Y seem to just be boolean:

class : mainwindow(QtGui.QMainWindow, Ui_test):
    def __init__ (self, parent = None):
        super(mainwindow,self).__init__(parent)
        self.setupUi(self)
        X = QtCore.QObject.connect(self.actionOpenX, OtCore.SIGNAL("triggered()", self.file_dialog)
        Y = QtCore.QObject.connect(self.actionOpenY, OtCore.SIGNAL("triggered()", self.file_dialog)
        QtCore.QObject.connect(self.actionProcess, QtCore.SIGNAL("triggered()", lambda : self.updateUi(X,Y))

def update_Ui(self, X, Y):
    for line in X:
        for line in Y:
            "do something"

def file_dialog(self)
    filedlg = QtGui.QFileDialog(self)
    self.filename = filedlg.getOpenFileName()
return self.filename

I am sure something like this is possible and I am having serious brain freeze atm.

many thanks in advance for any help

mike_pro
  • 115
  • 7

2 Answers2

1

The return value of QObject.connect is simply a boolean that indicates whether the connection succeeded or failed. It has nothing to do with the return value of the slot.

It seems from your example code that you want to get some filenames from the user in one step, and then process them in a separate second step.

In order to do this, the filenames need to be kept somewhere until the user decides to start the processing step. One common way to do this is to display the chosen filenames in a list-widget, or group of line-edits so they can be retrieved later. Alternatively, the filenames could simply be appended to an internal list (i.e. a private attribute of the class instance).

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • thanks ekhumoro - I hadn't thought about stoing the filenames like that - in a list widget. I will experiment with extracting the text from list widgets now as this gets past my dislike of global variables. – mike_pro Aug 01 '12 at 10:34
0

X = QtCore.QObject.connect(self.actionOpenX, OtCore.SIGNAL("triggered()", self.file_dialog) is return always a bool value so why dont give a try to use global vars like global x and set the x value in file_dialog ?

Achayan
  • 5,720
  • 2
  • 39
  • 61
  • I had thought about this Achayan, and infact this is how my current implementation is working, but it is somehow inelegant and doesn't sit well - I generally dislike global variables. I was hoping for a 'nicer' workaround if it was possible – mike_pro Jul 31 '12 at 20:42