cancel
Showing results for 
Search instead for 
Did you mean: 

Can we declare structure in model.hpp and how to use it in model.cpp ? any syntax , example or something

ABeck.1
Associate II
 
16 REPLIES 16

I thought you were using pseudo code in your last post. You can't pass a struct like that. You need to use the actual type which is a struct. e.g. in c++.

struct mystruct
{
    int a;
    int b;
};
 
....
 
 virtual void setStructValue1(mystruct s){}

Thank you,

In model.cpp

Model::Model() : modelListener(0), hour(0), minute(0),XY(5),AB(0),led_state(false)

{

   s.a = 1;

   s.b = 2;

}

void Model::tick()

{

 modelListener->setStructValue1(s); //que: HOW TO CALL THIS FUNCTION?

}

How to write  modelListener->setStructValue1(s);  ? This is wrong

../TouchGFX/gui/src/model/Model.cpp:55:42: error: expected primary-expression before 's'

 modelListener->setStructValue1(MyStruct s);

#error

You can't pass values like that. You're declearing a variable s of type MyStruct as an argument and that's illegal c++ (and C). Can I suggest you do an introductory course on C++? But for what it's worth...

//model.hpp: Declare s to be of type MyStruct to be used in the model
MyStruct s;
 
 
//model.cpp
s.a = 1;
s.b = 2;
modelListener->setStructValue1(s);

/Martin

modelListener->setStructValue1(s);

I have written this, still got error,

Do you have any TouchGFX project in that structure have saved in model and used in view.cpp? if so plz share with me.

Thank you.

I will surely work on your suggestion.

We have tons - Check any of the demos from the designer and look through the models and modellisteners.

Ya I have seen examples

I am able to pass integer values in between listener and view but with structure dayatype I haven't came across , which is my concern

I will check if I can get some

Thank you