namespace problems in pyqt

Mike Meyer mwm at mired.org
Sun Mar 30 13:17:59 EST 2003


Tom Chance <tomchance at gmx.net> writes:

> I've got a problem that's come about by not wanting to create a new 
> class for a dialogue box in PyQt. Previously, I had a class for the dialogue
> which included a function connected to a button in the dialogue. I made the
> class for the dialogue box in Qt Designer, imported that class, inherited
> it in a new class, into which I put the function (so it overrode the empty
> function declaration in the original class), like so:
> 
> class Inherited(QDialog):
>         /all the pyqt stuff/
>         connect signal to function2
> 
> class Inheritor(Inherited):
>         def function2:
>                 /so some stuff/ 
> 
> Now that function isn't in that dialogue's class... it's in the namespace
> that is calling the class instance, e.g.:
> 
> def function1(self):
>         /do some stuff.../
>         instance = Inherited()
> 
> def function2(self):
>         /do some stuff.../
> 
> How can I connect the button in Inherited to function2()? I've been told you
> can connect a Qt signal to a global function, but I can't work out how;
> I've tried declaring "global function2", and I've read through the Qt docs,
> but I cant' figure it out, so I'm obviously just being dumb and missing
> something here. Can someone give me a hand?

The answer depends on what "connect signal tofunction2" translates to
in real python. If you did something like:

        QObject.connect(source, SIG("signal()"), self.function2)

The you're already done. An instance of Inheritor that runs that code
- because it inherited it - in Inherited will connect to the function2
in Inheritor. That's one of the things inheritance is for.

If that's not what you did, show us the code so we can comment on it.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.




More information about the Python-list mailing list