[PySide] Passing parameter from one class to an external function
sebastian at risefx.com
Thu Apr 5 08:37:24 CEST 2012
Having a slot (your greetings function) outside a Class is never going
to work. This is from the Qt docs:
All classes that contain signals or slots must mention Q_OBJECT
<http://qt-project.org/doc/qt-4.8/qobject.html#Q_OBJECT> at the top of
their declaration. They must also derive (directly or indirectly) from
The last sentence is the most interesting for you. I suggest reading the
whole signal slots page, its very important. What you can do is this:
from PySide.QtCore import *
from PySide.QtGui import *
def __init__(self, parent=None):
self.edit = QLineEdit("Write my name here")
self.button = QPushButton("Show Greetings")
self.layout = QVBoxLayout()
print ("Hello %s" %form_instance.edit.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Form()
sys.exit( app.exec_() )
Am 05.04.2012 06:54, schrieb Frank Rueter | OHUfx:
> Not sure if I follow (I'm new to PySide myself).
> Your "greetings" function is outside the "Form" class, yet it takes the
> argument "self" and tries to call "self.edit.text()" which is unknown
> outside of the "Form" class.
> Hence my suggestion to simply increase the indentation of the function
> to make it a method to the class and things will fall into place:
> On 4/5/12 1:27 PM, craf wrote:
>>> just indent your "greetings" function so it becomes a method to the
>>> "Form" class, then it will work.
>> Hi Frank.
>> Thanks for your response, but the code is fine.
>> The function is outside the class, and I need to call it from within. In
>> WxWidget and Pygtk can be done, but I've failed PySide.
>> Any suggestions?
>> PySide mailing list
>> PySide at qt-project.org
> PySide mailing list
> PySide at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide