2024-09-26 08:44 PM
Hi, I went through some other discussions discussing a similar problem, but they did not seem to help.
I have screen one which displays (dynamically) a container. The container has a button on it, which when clicked, changes screens to screen 2. At the same time the container needs to send data to screen 2 (an int). The button is a flex button which I set up from the GUI call a virtual function.
I would prefer a way where the container is not permanently tied to screen 2, as this container appears on multiple screens and does something similar.
Solved! Go to Solution.
2024-09-30 01:14 AM
That is (one of) the issue with dynamic. I think your best bet is to store each of your element in an array or vector.
Regards,
2024-09-27 07:05 AM
Hello @Priyank ,
What seems to be the problem exactly?
To me it seems that you want to have the same widget in multiple screens but this is not possible, you just have to add it to each screens individually to end up with the intended result.
When you click your button, you call a function doing 2 things :
I would advise you start by sending the data to the model and then you change the screen to be safe.
Overall, just add your widget to each screens and start by sending your data before switching screen and your design will be fine.
I hope this helps! :smiling_face_with_smiling_eyes:
If this comment answers your question, I invite you to select it as "best answer".
Regards,
2024-09-27 07:09 AM
Thank you, here is is some more context:
I am adding these containers to each screen that needs it
I am just having a problem with getting the container to send data to the view/model. The tutorials say to use callbacks but I can't get that to work. Some are also binding the container itself to a view, but I don't want that because this container will be on many screens.
2024-09-27 07:14 AM
I am adding these containers to each screen that needs it
That is fine, I do it like that too myself.
I am just having a problem with getting the container to send data to the view/model. The tutorials say to use callbacks but I can't get that to work
Which tutorial are you following?
I advise you to look at these tutorials :
Some are also binding the container itself to a view, but I don't want that because this container will be on many screens.
What do you mean by "binding the container to the screen" ?
Regards,
2024-09-27 07:17 AM
I'm used Tutorial 3 method for most of my data sending but I'm not sure it would work in thi ssituation because
1. the container shows up on the screen dynamically (it may appear once, twice, three times,etcA)
2. the container does not have a presenter to interact with the view/model
3. the button which is used to click the container is apart of the container itself
So, am I right to assume the data has to be sent through the container files? This is what I am thinking, but can't find a way to send the data from a container to a model/view
2024-09-27 07:29 AM
1. the container shows up on the screen dynamically (it may appear once, twice, three times,etcA)
It is not recommended to add elements dynamically, especially in your case, because how do you plan on getting access to containerName.mydata? What is the name of the containers you create dynamically?
Maybe you should add the maximum number in your GUI and set them as invisible.
2. the container does not have a presenter to interact with the view/model
Yes, but you can access it throught the screen it is in.
Such as : ContainerName.MyData.
Example:
In the container.cpp I add "int myData = 10;"
In the screen.cpp I add "touchgfx_printf("\nVal is : %d.", customContainer11.myData);"
I am able to correctly print the value 10.
3. the button which is used to click the container is apart of the container itself
Then, clicking the button should call a function (in the screen.cpp), in this function, you can access the value of the container such as "containerName.dataName" and send it to the presenter of the screen you are in.
So, am I right to assume the data has to be sent through the container files? This is what I am thinking, but can't find a way to send the data from a container to a model/view
The data starts from the container, goes to the screen, then presenter, then model.
Regards,
2024-09-27 07:38 AM - last edited on 2024-09-27 07:49 AM by GaetanGodart
Gotcha, so most of what you said is only possible if the container is added to screen from gui and set invisible right? I planned on doing it dynamically is because the container is called product for example. The user can have anywhere from1-48 products which will appear on the product screen. I wanted to save space by dynamically adding only the amount of products they have. When I dynamically added the product container I also assigned the container an id for identifying it meaning the product container cpp/hpp has a variable for id. Would this be inefficienct? I am open to populating 48 products on the scroll wheel which they appear on, and keeping them invisible. However, it comes down to efficiency/memory usage, would setting 48 product containers be more efficient than dynamically added only the amount of products that the user has?
2024-09-27 07:53 AM
If you have a way to access the containers that you add dynamically it should be fine, it should work.
I don't think you will see performance difference and in either cases, your project would run without issue. Saving memory here doesn't seems necessary because it is not critical, therefore, it is up to you to implement it the way you prefer.
Regards,
2024-09-27 07:54 AM
Thank you, so if I keep it dynamic, how would I deal with sending the container id to the view/model? Since there is no presenter
2024-09-30 01:14 AM
That is (one of) the issue with dynamic. I think your best bet is to store each of your element in an array or vector.
Regards,