Re: Problem of inheritance
Well your starting point is wrong. How could MainWindow know that it will be base class to WorldGui? So there is no direct possibility to do so.
If you know in MainWindow that it should use a function of WorldGui, then direct implement it there. Or use a complete different design approach.
Re: Problem of inheritance
Quote:
that is called through the mechanism of Signal/Slot of MainWindow.
Within this function I would want to call a function of WordlGui
When you say signal/slot of MainWindow, it should mean that MainWindow is a QObject based class (if not QWidget), which will lay a restiction on the inheritance sequence.
Please show us the class definition of "World" and "MainWindow", or at-least tell us what those are based on.
Quote:
how can I do ?
I could get an example of code that tell me how to do ?
I'm going crazy with this problem, which I think is not that difficult, but I can not find the solution.
There are things which one cannot do in Qt (at-least out of box). Please show us more about what are you really looking for.
Re: Problem of inheritance
Quote:
Originally Posted by
giorgik
Hello everyone, I am a inheritance problem ...
No, you have a design problem. MainWindow should not need to directly call anything on WorldGui. If MainWindow cannot do its job without using WorldGui, then MainWindow is not complete and should not form part of WorldGui - this would be a circular dependency.
Re: Problem of inheritance
Thank you all for the answers. In fact, I poorly designed classes. The solution is to use a class WorldGui that does not derive from MainWindow, but use a pointer to MainWindow as a member variable of WorldGui. Then use the technique of signal/slot to communicate MainWindow with WorldGui.
Re: Problem of inheritance
Re: Problem of inheritance
Quote:
The solution is to use a class WorldGui that does not derive from MainWindow, but use a pointer to MainWindow as a member variable of WorldGui. Then use the technique of signal/slot to communicate MainWindow with WorldGui.
I don't see any problem with this approach, go ahead and do it. One note is to inherit WorldGui from QObject
Re: Problem of inheritance
Quote:
Originally Posted by
amleto
no, just no.
Could you please elaborate on that? I use similar approach sometimes and it would be good to hear about downsides.
Re: Problem of inheritance
I would probably do it the other way around, i.e. letting the UI class have a pointer to the non-UI/logic class. This way the logic is more independent of the concrete UI implementation and UI can be changed more freely.
Cheers,
_
Re: Problem of inheritance
Quote:
Originally Posted by
lanz
Could you please elaborate on that? I use similar approach sometimes and it would be good to hear about downsides.
by changing inheritance for composition the overall design hasn't changed, just the implementation. It appears that the two concrete classes still cannot do a job by themselves, and still require each other to do a job.