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. How to have one logic object with multiple custom widgets for representation?

How to have one logic object with multiple custom widgets for representation?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.0k Views
  • 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.
  • A Offline
    A Offline
    AlexanderL
    wrote on last edited by
    #1

    Hi there,

    I want to write an application where I have one separate object handling the logic to which I can connect 1 to n independent custom widgets. These custom widgets should be able to send user input to and represent data from the logic object. I want to do this without having to change the implementation of the logic object itself, such that there is a clean separation between gui and logic.

    For better understanding, a simplified/random example of what i want:
    Let's say i have a logic object (and there must be only one object of this class) which has three strings A, B, C and updates them via network I/O. Furthermore i want to have a custom widget X which displays strings A and B an has a button to the tell the object to update the strings and a custom widget Y which only displays strings A and C. The custom widgets should update their displayed information if there's a change in the logic object.

    I'm currently using Visual Studio 2010, Qt Designer and the "member variable approach ":http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html#using-a-member-variable to create the custom widgets. I put them together in the main window ui file with the "promote to" command.

    So far, I have the logic object as member variable in my MainWindow class and WidgetX and WidgetY included in the MainWindow, as described above.

    Question 1: Now I want to connect one of the widgets with the logic object and do the following in the constructor of the MainWindow class.
    @connect(ui.widget->ui.pushButton, SIGNAL(clicked()), &logic, SLOT(doStuff()));@

    It doesn't compile since the member WidgetX::ui is private. I have no idea what to do against this.

    Question 2: Is there a better aproach than mine?

    If you're going to say read the model/view programming article: I find it hard to understand and also it only revolves around the representation of data (e.g. databases or filesystems) which didn't bring me any further.

    I want to do this as clean as possible and have googled a lot but didn't find an answer, so i'd even be happy if you could provide me some keywords to google for.

    Regards, Alex

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlexanderL
      wrote on last edited by
      #2

      Update: I've figured out what my problem was. I have to do the connects in the constructor of the corresponding object itself, not in the MainWindow class. To avoid that there are multiple instances of my logic object (which would probably cause troube since it does network i/o) i used the "singleton pattern":http://www.qtcentre.org/wiki/index.php?title=Singleton_pattern#Template-based_Approach .
      So in every custom widgets constructor i do the following: @Logic *logic = &Singleton<Logic>::Instance();@
      I think the approach is okay and so far, it works.
      But still, if you know better design approaches, i'd be happy to hear them!

      1 Reply Last reply
      0

      • Login

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