views:

64

answers:

1

I am a newbie with PyQt4 (and QT altogether), and am facing a problem,

I have subclassed QApplication (to have global data and functions that really are global to the application):

class App(QApplication):
    def __init__(self):
        QApplication.__init__(self)
        self.foo = None

    def bar(self,x):
        do_something()

When I try to add a slot to my main window like:

self.connect(bar, SIGNAL('triggered()'), qApp.bar)

I get an error: AttributeError: bar

What am I doing wrong? Or should I make the stuff I want global, global stuff instead off attributes and methods of QApplication subclass? (or something else, if so, what?)

Note: this all worked fine when the "global" methods and attributes were in my QMainWindow -subclass...

+1  A: 

Try adding QtGui.qApp = self to your __init__ method (or try using QApplication.instance() instead of qApp).

I hope that helps.

Greg S
The former approach didn't work, `QApplication.instance()` did the trick. Thanks!
Kimvais