Skip to main content
apll
Associate II
March 14, 2019
Question

How can it use model function out of MVP?

  • March 14, 2019
  • 7 replies
  • 1490 views

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.

This topic has been closed for replies.

7 replies

cameronf
Associate
March 14, 2019

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.

Martin KJELDSEN
Principal III
March 18, 2019

@Community member​,

When exactly do you want to use the MainApp class? From within your view?

apll
apllAuthor
Associate II
March 18, 2019

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.