0

I am writing a code for a GUI in c++ using wxwidgets. In the GUI I have an input panel that recieves information from the user, and an output panel that displays the results of a numeric simulation based on the received data. How can I transfer information from the input panel to the output panel? Is it possible to have a global structure that belongs to the parent wxwindow, or better yet, to wxapp, such that all children windows and panels have read and write access to this structure? (looking online, it seems wxclientdata might fit what I'm looking for, but I can't figure out how to use it in the way I described above, or whether it is at all possible).

4
  • 1
    You may want to use the Model-View-Controller design pattern. Let the Controller read from the GUI and store into a common database (the Model). The Viewer can take data from the model and display it. In any case, your issue can be resolved by using a third party object or widget. Commented Aug 11, 2024 at 3:42
  • You could have a Start button that initiates the process. The button handler would read the data, perform the operations, then post the data to the output widget. Commented Aug 11, 2024 at 3:43
  • 2
    Or just create a custom event and have the second widget react to it when the first one emits it, ie bind it when creating the two widgets. You don't want one widget calling methods on the second widget directly as you want loose coupling. Commented Aug 11, 2024 at 7:20
  • Ok, I read quite a bit about custom events etc, but I still don't understand how will the data be shared between the different panels or classes. For instance, say I have an input wxpanel that contains a table in which the user will input the data and an output wxpanel where the processed data will be presented. I can call a custom event that will do the processing, but how will the custom event have access to the input data? and how will the output wxpanel get access to the processed data? Is there a way to generate a common database between the wxpanels? Commented Aug 19, 2024 at 4:53

1 Answer 1

0

In general, when UI objects receive inputs and they don't know (or shouldn't know) where those inputs will be used, I have them tell the App object. That is, I'll write a method in the App class, something like User_Requests_The_Oven_Timer_Be_Set(), or User_Provided_Their_Shirt_Size(int size), or the like. The UI can call that method whenever. Then the App can do whatever calculations, lookups, or other actions it needs to do, and then it can tell the UI to display the results.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.