Unsolved Best approximation to a QWidget controller -> view schema
-
Hello,
I am trying to develop an application that can have multiple instances of a Widget that, let's say, connects to an API and synchronizes some data and saves it to disk.
I have a QFrame (let's call it MyWidgetView) for the view, with a Start/Stop button, several labels to display information and 2 combos to select what data from the API needs to be synchronized.
Then I have a QObject (let's call it MyWidgetController) that does the job of connecting to the API, processing the data, generating a CSV file, etc.
Finally, in the MainWindow class, I create as many pairs of MyWidgetView and MyWidgetController as I need, assigning a Controller instance to its view and then adding the view to a horizontalLayout.
When I click the Start button of the view, I can call the controllers' start() method, since I have a pointer from the view to the controller.
But when I want to update the view given some event produced on the controller, what should I do?
- Connect the controller to the view through a "updateView()" signal and then from the view query for the data required? (this is my current approximation, but ineficient when the view grows)
- Create as many signals as needed? updateCombo1(), updateLabelRemaining(), updateBackgroundColor(), ...
- Pass a pointer of the view to the controller, just as I pass a controller pointer to the view?
Is this approximation of linking view and controller correct? Am I missing some step?
Thank you so much.
-
Hi, and welcome to the Qt forum! Your controller shouldn't have any knowlegde about the user interface. So, no updateCombobox signals etc. Expose the data that the UI should read / write as properties in the controller and connect the UI to them via signals.