Reputation: 49
I have a GUI application with some widgets. I want to implement a mechanism that will enable widgets to "register" to event (from a list that that I define) and when event will occur the "Refresh" method of all the widgets that registered to this event will be called.
I thought about declaring a "Refreshable" interface with the "Refresh" method.
My main problem is that any implementation that I could think of (I mainly thought about implementing it with signals and slots) will require the Refreshable interface to inherit from QObject
(so some meta-data will be stored and I'll be able to use signal and slots), and this means that widgets will not be able to derive from Refreshable because they already inherit QObject
via QWidget
.
Any help/ideas will be highly appreciated!
Upvotes: 1
Views: 2668
Reputation: 7278
You are trying to design a solution which is already provided in Qt well enough. Each QWidget has slots repaint()
(forced immediate) and update()
(queued deferred). That is about everything you should ever need for your refreshability. In other words, QWidget already implements what theoretically would be your Refreshable interface. And yes, you are right on the observation that you can't inherit from QWidget and yet another "interface" which must inherit from QObject too in order to be able to declare a slot. I think it will become clearer if you stop calling it interface because technically it's not - at least in the sense of pure virtual class.
Upvotes: 3