2019-03-14 01:52 AM
Hi!
I want to use a function of the model in a my class out of MVP, is it possible?
void Model::proofPrint()
{
modelListener->printLabel();
}
printLabel() is a function inside a screen.
I have a class MainApp.cpp that it use how class wrapper for the file DebugConsole.c.
MainApp isn't a screen.
How can i use model.proofPrint in MainApp?
Obviously i call proofPrint when i am in the correct screen.
2019-03-14 09:51 AM
If you want direct access to the model instance you can add functionality to the Model that lets it pass out a reference to itself and then use that reference to make calls to the model (like setting a static pointer in its constructor and adding a static getter function for that pointer).
You can also pass messages into the model from you main logic with a queue and have the Model poll that queue at the beginning of its tick method and tie a specific message to calling your printLabel method. I think of this as being cleaner but I could see arguments for wanting direct access to Model in certain cases.
2019-03-18 01:43 AM
@Community member,
When exactly do you want to use the MainApp class? From within your view?
2019-03-18 02:16 AM
I am in layoutView where it has scrollcontainer and some button, but scrollcontainer has a custom container with many object.
I digit a command with UART and i want call a function inside my custom container but i can't access because the class with UART command isn't a screen so i can't use model function...
Now i resolve using a global variable when i send command UART exact i set a 1 this variable and into model tick i call the currect correct function in the presenter of layoutView.
2019-03-18 02:26 AM
You can initialize the class with a reference to the presenter, then call a function on there. The presenter knows the model so it can redirect the call.
/Martin
2019-03-18 02:35 AM
MainApp or labelLayout (custom container)?
LabelView already has reference to Model.
2019-03-18 03:17 AM
It doesn't really matter which of the two (Custom Container or MainApp class) you pass the reference to - depending on how you're using MyApp internally. The important thing is that neither of them know the model and they can know the model through a presenter reference.
/Martin
2019-03-18 07:18 AM
How do i make to add a presenter reference?
class LabelLayout : public LabelContainer, public View<LayoutPresenter> {
This generate error of compiling.