I am working on an application to manipulate simple graphical geometry with associated attributes for several regions organized in a parent child relationship, e.g. there could be three super elements each containing two regions with the graphical elements. I am building this with Qt using a QGraphicsScene for the layout inside the applications QMainWindow, and a seperate window to manage the graphical elements in each region.
It is currently setup in a way where a Layout class sets up the supers and the supers create their regions and the Manager class that controls graphical elements and the seperate window.
To add another case, each region also may create a TCP client to connect to some server and receive messages to be displayed graphically, and this client could encounter an error which currently is displayed using a static QMessageBox method.
Generally speaking, I am mixing custom classes with Qt classes in an object hierarchy where child elements sometimes need to access the root parent around which the GUI is based (MainWindow).
- Since many of these objects need to access the QGraphicsScene, I currently use a mix of accessing it via a number of parent() calls or by passing the scene's pointer.
- I sometimes use Qt's signal-slot mechanism in attempt to create better separation through interfaces, but this creates overhead (and I am not sure what the advantages are [except for thread safety] compared to calling methods via object reference)
- Not all objects in the hierarchy inherit QWidget, so the "parent" reference does not always work e.g. for the QMessageBox modality
I know this is a vague question but I am only looking for general hints on how objects in a typical GUI hierarchy are supposed to interact and how Qt's Signal-Slot mechanism is used best.
Should I always pass a reference to MainWindow in my classes? Should I keep that reference globally? Should children e.g. not display message boxes but emit a signal for the MainWindow to show (but then how would the child get the user input?)?
What is this problem generally called?