cancel
Showing results for 
Search instead for 
Did you mean: 

How can I Save and Get data from Model in touchGFX

HAnh
Associate III

Hi everyone.

I have built many screens, and in every screen I have many single data and array data.

About single data I can transfer them to other screen, by save them to model when I close screen.

But I don't know how to save Array data (like Time [10]) to model when I close screen and get them when I active scree.

So Anyone can give me some advice to solve my problem

Thanks and best regards.

7 REPLIES 7
Alexandre RENOUX
Principal

Hello,

Please have a look at the following article on our documentation website : https://support.touchgfx.com/docs/tutorials/tutorial-03

This should help you.

/Alexandre

HAnh
Associate III

Hi Alexandre RENOUX.

I have read Tutorial-03,and can transfer data to another screen via model, but it only single data like uint_8, uint_16.

Everything I need, that is I can transfer Array data to another screens line Time[10], Date[30].

Because if I using single data, it very long and must using many single data.

So can you help me in this case.

Thanks and best regards.

Alexandre RENOUX
Principal

I see that you are not familiar with c and c++ programming. In these languages, you have something called pointers.

https://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm

/Alexandre

HAnh
Associate III

Yes, You right, I'm not familiar with c and c++ programming, thanks for your share.

But I don't know how to declare Array in the model.ccp like:

Model::Model() : modelListener(0), hour(0), minute(0)

{

}

in my know, hour(0) and minute(0) is single variable, but now I need declare Array in this that.

I tried to declared as bellow:

Model::Model() : modelListener(0), Array1[10],*Array2

{

}

But is don't correct.

Can you show me, how to declare Array in this case.

Thanks you so much.

Alexandre RENOUX
Principal

Simply write in Model.hpp

int array1[10];

I don't know if you are trying to use int or not but just put whatever type you need.

This forum is not meant to teach people how to code in c or c++. Please look on the internet for how to declare arrays, what's a a class, a constructor, ...etc

/Alexandre

HAnh
Associate III

Hi.

Maybe you don't read my question carefully.

I asked that how to declare Array in the model.ccp like some single variable like:

Model::Model() : modelListener(0), hour(0), minute(0)

{

}

Absolutely before that I must declared in model.hpp:

int array1[10];

In my know, hour(0) and minute(0) make initiate value for hour and minute variable, but now I need declare Array in this that.

I tried to declared as bellow:

Model::Model() : modelListener(0), Array1[10],*Array2

{

}

But is don't correct.

My bad.

If you want to initiate the values, simply do it inside the brackets

Model::Model() : modelListener(0)
{
     // Do it here but here is an example
    for(int i = 0; i < 10; i++)
    {
        array1[i] = 0;
    }
}

/Alexandre