PDA

View Full Version : Dynamic plugin: accessing parent's methods



codeslicer
4th January 2011, 03:28
Hi,

So if I have a custom QPlugin, is it somehow possible to access its parent's methods by casting the parent() property to the main class? Im getting problems because when I include the parent header file in the plugin, they are not virtual so moc complains... I.e. Undefined references. Thanks!

wysota
4th January 2011, 09:16
It's highly against OOP principles to do such a thing. If you rely that the parent is always of class X then when setting a parent, accept a pointer to X and store it in a variable to X. Then no cast will be required and nobody will use your class in a way that could break it (i.e. by passing a parent of different class).