I have a Python module with two classes, MainWindow (which inherits from QMainWindow) and MyView (which inherits from QGraphicsView). In the MainWindow I have a MyView which should set some variables in the MainWindow class. So I figured I just put the reference to my MainWindow object into a global variable and let the MyView access it like that. Here's the code:
class MyView(QtGui.QGraphicsView):
    def __init__(self, parent = None):
        super(MyView, self).__init__(parent)
    def mousePressEvent(self, event):
        super(MyView, self).mousePressEvent(event)
        print "Mouse Pointer is currently hovering at: ", event.pos()
        global myapp
        print "myapp value is: ", myapp
myapp = None
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MainWindow()
    print "myapp assigned, value is: ", myapp
    myapp.show()
    sys.exit(app.exec_())
After clicking on the MyView the program output is this:
$ ./main.py 
Gtk-Message: Failed to load module "canberra-gtk-module"
myapp assigned, value is:  <__main__.MainWindow object at 0x7fc29e1ed640>
Mouse Pointer is currently hovering at:  PyQt4.QtCore.QPoint(172, 132)
myapp value is:  None
Why is this? I'm not setting "myapp" to a different value, in the posted code are all occurcences of it.
 
     
     
    