Communicating between frames/dialogs

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Terran
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Apr 30, 2008 12:35 pm

Communicating between frames/dialogs

Post by Terran »

Ok so lets say i have my class;

Code: Select all

class data
{
   public:
      wxString returnName() const { return Name;}
      int returnCost() const { return cost; }
   private:
      wxString Name;
      int cost;
}
and i want to be able to use my add dialog to create a new one, and pass it to a list in the parent frame.

How?
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Re: Communicating between frames/dialogs

Post by mc2r »

Terran wrote:and i want to be able to use my add dialog to create a new one, and pass it to a list in the parent frame.

How?
Short answer, get a book on c++ and read it. Because I'm not a complete dick the longer answer.

new is used to create a new object. To pass it to the parent frame the add dialog will have to have a pointer to the parent frame. So you will have to pass one in to the add dialog, probably when it is created. This is just the opposite data::returnName(). The parent frame then needs a function as well to add new data that takes the new'd data* and adds it to a list or whatever you are using to store them.

But really back to dick mode. Not only is this is all basic c++, but it has been asked here numerous times and spending a little time searching the forum probably would have found you the answer. This is stuff you will need to learn if you are doing any c++ coding not just wxWidgets. Pretty basic but crucial stuff.

-Max
Terran
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Apr 30, 2008 12:35 pm

Post by Terran »

Wow, that really was a dick answer.

Sorry for not understanding how wxWidgets interacts with C++, because unlike what you've stated, using wxWidgets is not the same as basic C++.

I know it's not the point, but why would you even bother posting an answer if all you were going to do was beret me for asking a question on a forum designed for asking questions? Yeah you're right, my bad.

And heck, maybe if you had spent that much effort to try to answer it, the next time somebody has this question, they won't happen upon a thread of hostility and they might not have to ask it again. What an idea!

[/b]
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Terran wrote: Sorry for not understanding how wxWidgets interacts with C++, because unlike what you've stated, using wxWidgets is not the same as basic C++.
I agree with mc2r that your issue is lack of knowledge in C++. Using wxWidgets is not the same as basic C++, but your issue seems to be dealing about lack of understanding about classes and pointers

I do not mean to be rude, it's just that if you lack C++ knowledge, wxWidgets is not the right place to start. If you think you know enough C++, then try writing a little more code than the few lines you posted
Terran
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Apr 30, 2008 12:35 pm

Post by Terran »

Auria wrote:...try writing a little more code than the few lines you posted

I understand fine how classes and pointers work, i don't undertsand how wxWidgets manages the flow of information from widget to parent.

So if i call my Add dialog from the dialog that holds the list, how do i pass that info back to the list?

Code: Select all

void BillDia::OpenAdd(wxCommandEvent& event)
{
    MyDialog1 *addBill = new MyDialog1(this);
    addBill->ShowModal();
}
i understand that i can catch the id of buttons pressed buy watching the dialog pointer, but how do i watch for several pieces of info passed back from text input boxes?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I recommend you look at the samples and docs to learn more about Event Handling

For instance : http://docs.wxwidgets.org/stable/wx_eve ... ngoverview

Then you can react when the user does something

(Perhaps you should elaborate a little more, it's not always obvious precisely where you're stuck)
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

Pretty much what I do is keep a list of whatever data I need in the parent frame. Then with my subsequent dialogs, create a new constructor for that dialog, that expects a pointer to that list. Then when the dialog manipulates that list, the parent already has a copy of it.

Code: Select all

myFrame : public wxFrame
{
      wxList *myList;
}

Code: Select all

myDialog :wxDialog
{
       myDiaog();
       myDialog(wxWindow* parent, wxWindowID id,
               const wxString& caption, 
               const wxPoint& pos, 
              const wxSize& size, long style); 
       
       //new constructor
       myDialog(wxList *list,
               wxWindow* parent, wxWindowID id,
               const wxString& caption, 
               const wxPoint& pos, 
              const wxSize& size, long style);
}
I use this setup for a bunch of my mini dialogs created inside my main frame.
Terran
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Apr 30, 2008 12:35 pm

Post by Terran »

Auria wrote: (Perhaps you should elaborate a little more, it's not always obvious precisely where you're stuck)
Although that link did (and will) help, it doesn't answer my question completely, i'm trying to figure out how to extract the info from text boxes in the dialog to store them in my data object. I'm not sure how to do it. (i know WHERE; in the event for the "Add" button.)
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

i'm trying to figure out how to extract the info from text boxes in the dialog to store them in my data object.
try wxTextCtrl::GetValue();

should return the contents of the text control.
then set that equal to the next item of your list that you passed into the dialog(if you chose to set it up that way).
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg »

If you want to pull info out, just do it after ShowModal returns.

Code: Select all

void BillDia::OpenAdd(wxCommandEvent& event)
{
    MyDialog1 *addBill = new MyDialog1(this);
    addBill->ShowModal();
    mydatastring = addBill->myTextCtrl.GetValue();
}
Of course, you might want to check that the user didn't hit the Cancel button in the dialog first.

Code: Select all

    if(addBill->ShowModal()==wxID_OK)
    {
        mydatastring = addBill->myTextCtrl.GetValue();
    }
}
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

Terran wrote:
Auria wrote:...try writing a little more code than the few lines you posted

I understand fine how classes and pointers work, i don't undertsand how wxWidgets manages the flow of information from widget to parent.
This is my point. wxWidgets manges the flow of information from widget to parent using normal c++. If you understand fine how this works than doing the same in wxWidgets should be no problem for you. The fact that you are hung up on there being a difference is further evidence that you should brush up on your c++.
Terran wrote:So if i call my Add dialog from the dialog that holds the list, how do i pass that info back to the list?
This is what we are talking about. This is a c++ thing and is where you need to brush up. Forget that it is a dialog or widget or panel or frame or wx*, they are all c++ classes and so c++ rules and convention applies.

-Max
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

timg,

Code: Select all

mydatastring = addBill->myTextCtrl.GetValue(); 
Wouldn't that mean that the textCtrl would have to be a public member of the dialog?
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

Terran wrote:Wow, that really was a dick answer.

Sorry for not understanding how wxWidgets interacts with C++, because unlike what you've stated, using wxWidgets is not the same as basic C++.
Don't be sorry, just take the advice(or not, its your call). But that you think it isn't the same as basic c++ is my very point. It is the same. Having solid c++ skills will go a long way to helping you understand wxWidgets as wxWidgets is all C++.
Terran wrote:I know it's not the point, but why would you even bother posting an answer if all you were going to do was beret me for asking a question on a forum designed for asking questions? Yeah you're right, my bad.
Thats not all I did. I told you to get a c++ book, which you may not like but from this post and others you've made you need. I know I know you understand c++ just fine as you keep asserting but your posts suggest otherwise. Don't be offended you are here to learn right? Then work on your c++ it will help you a lot with your wxWidgets.

I also answered your question as complete as I could with the question you asked. if you would like better/more complete answers as better more complete questions. There is a link at the top of the page to post a question for asking questions the smart way. Read it.

And then I reiterated the final and most crucial point, improving your c++, and you really do need to or you are in desperate need of reading asking questions the smart way, will go along way to helping you.

And last these questions have been asked and answered numeral times. And I mentioned that you should search the forums. And you should.

-Max
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Terran wrote:
Auria wrote: (Perhaps you should elaborate a little more, it's not always obvious precisely where you're stuck)
Although that link did (and will) help, it doesn't answer my question completely, i'm trying to figure out how to extract the info from text boxes in the dialog to store them in my data object. I'm not sure how to do it. (i know WHERE; in the event for the "Add" button.)
There are many steps involved in this; which one causes problems?

In the event callback, get the data from the controls (see the docs of the corresponding controls to know what methods you can use to get data) then send this data to wherever it belongs by using a pointer to the appropriate class and calling a method in it
Post Reply