Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best approximation to a QWidget controller -> view schema
Forum Updated to NodeBB v4.3 + New Features

Best approximation to a QWidget controller -> view schema

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 620 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JoaquimBSJ Offline
    JoaquimBSJ Offline
    JoaquimBS
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved