cancel
Showing results for 
Search instead for 
Did you mean: 

Model-View-Presenter

AS5
Associate II

Hi everyone,

I’ve been trying to implement a mechanism to save two matrices (each containing values of type Unicode::UnicodeChar*) and an errorCount variable using the Model-View-Presenter (MVP) architecture in TouchGFX. The issue arises when transitioning from one screen (Screen1, Screen2, etc.) back to the main screen (Screen), where the matrices are not saved correctly, although errorCount is successfully stored.

Here is the application structure:

  • The main screen (Screen) contains buttons leading to Screen1, Screen2, ..., Screen5, where each screen represents a separate Sudoku game.
  • Each of the Sudoku screens (Screen1–Screen5) has a button to return to the main screen (Screen).

The goal is to ensure that, when navigating from any Sudoku screen back to the main screen, the following data is preserved:

  1. NumberMatrix (matrix storing Sudoku numbers)
  2. NoteMatrix (matrix storing Sudoku notes)
  3. errorCount (number of mistakes)

I have successfully implemented the mechanism to save and retrieve the errorCount, but the matrices (NumberMatrix and NoteMatrix) are not being saved correctly.

Here is the issue:

  • When navigating from Screen1 to Screen, the errorCount is correctly saved and restored.
  • The matrices (NumberMatrix and NoteMatrix) are not saved properly. After returning to the screen, their values are either empty or incorrectly set.

Code Implementation:

  1. Model.cpp:
    In the Model class, I’ve implemented functions for saving and retrieving the matrices and the errorCount. I use Unicode::strncpy to copy the contents between the matrices. Both matrices are initialized with empty strings ("").

  2. Screen1Presenter.cpp:
    Presenter functions call the appropriate methods in the Model to save and retrieve the matrices and errorCount.

  3. Screen1View.cpp:
    In the setupScreen and tearDownScreen methods, I call the Presenter functions to save and retrieve the data.

Have you encountered a similar problem in TouchGFX? If you have any suggestions on how to correctly implement saving and restoring matrix data using MVP, I would greatly appreciate your help.

Best regards,
@AS5

0 REPLIES 0