PyQt Variables
Diez B. Roggisch
deets at nospam.web.de
Thu Jan 5 15:46:20 EST 2006
gregarican schrieb:
> I have an application I'm writing using PyQt. I'm trying to create the
> various windows by subclassing Qt objects. I have a subclassed
> QMainWindow as the parent, and then a series of subclassed QWidgets as
> other child windows that get used. How can I pass variables back and
> forth between the parent and child windows? For example, if I have a
> child window that processes a customer lookup I want the retrieved
> values to be passed back to the QMainWindow. I have tried using global
> variables, but these variables seem to be global only in the sense of
> each subclassed object. Not between the subclassed objects.
Looks (or better smells) like a design smell to me. In Qt,and especially
PyQt, you rarely subclass widgets, as that makes you lose the
possibility to use the fabulous designer. The only thing I subclass in
PyQt are the designer-generetaed top-level-classes. Can be a widget, or
sometimes dialogs.
QObjects usually communicate using signals/slots. That ensures a nice
weak coupling of components and enforces good MVC design. If you
absolutely must share state by means of instances of widgets,
explicietly introduce them to each other. No globals needed!
Additionally, what you experience is the fact that python only knows
module-global variables. See
http://www.faqs.org/docs/diveintopython/dialect_locals.html
for an introduction.
Regards,
Diez
More information about the Python-list
mailing list