Communication between objects (parent and child)
-
Hello everyone,
I wonder how to implement communication between classes and objects hierarchy like parent and child?
For example, I'd like to make authentication system for multiwindow application, so I guess I need an object to store information that user is logged in and which user it is. But if I make it in one class (for example AuthUser) and I'll make few more objects (maybe QDialogs) from different class (fo example AppEngine) then how to implement communication between all these objects?
And what if some objects create other child-objects? How to make all these objects communicative to each other, for example to verify authorization and allow or disallow execute their methods?
-
Hi!
For this case you can use "signal&slot":http://qt-project.org/doc/qt-4.8/signalsandslots.html -
I know that, but I don't know how.
How to receive signal from parent object?
Send to child is easy, but I don't know how to receive that signal.MyWindow newWindow;
connect(this, SIGNAL(someSignal()), newWindow, SLOT(someSlot());But what in child?
connect(parent??, SIGNAL(someSignal()), this, SLOT(someSlot()); -
I do not see how AuthUser fits in into a parent/child relation with dialogs.
If you only ever have one user authenticated you could make AuthUser a singleton and access it like any singleton object.