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 [qt-project.org] 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
↧