Change instance of other frame

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
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Change instance of other frame

Post by mxoliveira73 »

Orientation about change object in other frame, please.

newDialog ( ButtonZ -click ) ----- (Setlabel of object in mainFrame)


something like this:


void NewDialog::OnButtonZClick(wxCommandEvent& event){

mainFrame::Button1->Setlabel("lalala");

}
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: Change instance of other frame

Post by alys666 »

to change instance you must give it. Not a class of this instance.

Code: Select all

void NewDialog::OnButtonZClick(wxCommandEvent& event){
	__mainFrameInstance->Button1->Setlabel("lalala");
}
Where __mainFrameInstance is a pointer to instance of class MainFrame, created by new(..)

you write -
int MyInt = 10;

you do not write
int = 10;

Class is a type. instance is an object of this type.
ubuntu 20.04, wxWidgets 3.2.1
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: Change instance of other frame

Post by mxoliveira73 »

mainFrame * __mainFrameInstance = new mainFrame(0);

void NewDialog::OnButtonZClick(wxCommandEvent& event){
__mainFrameInstance->Button_mainFrame->SetLabel("lalala");
}


this code compile whitout errors;

but clicking in the ButtonZ, Button_mainFrame don't SetLabel("lalala");
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Change instance of other frame

Post by evstevemd »

Code: Select all

class MyDialog: public wxDiaog
{
	public:
	MyDialog(MyFrame *parent): wxDalog(parent....){}
	
	void ShowLalala(){
		MyFrame *frame = dynamic_cast<MyFrame*>(GetParent());
		if(frame) frame->SetMyText("Lalalalaaaa");
	}
};

//then MyFrame
class MyFrame : public wxFrame
{
	public:
	MyFrame(wxWindow* parent): wxFrame(parent){}
	void SetMyText(const wxString& text)
	{
		m_buttonInTheText->SetLabel(text);
	}
}

//using it
MyFrame *f = new MyFrame(NULL);
..
..
..
MyDialog dlg(f);
dlg.ShowLalala();
That is the concept you can use to develop your solution!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change instance of other frame

Post by ONEEYEMAN »

Hi,
mxoliveira73 wrote: Thu Jun 13, 2019 11:49 am mainFrame * __mainFrameInstance = new mainFrame(0);

void NewDialog::OnButtonZClick(wxCommandEvent& event){
__mainFrameInstance->Button_mainFrame->SetLabel("lalala");
}


this code compile whitout errors;

but clicking in the ButtonZ, Button_mainFrame don't SetLabel("lalala");
This is a basic C++ question.
You should learn and understand the features of the language prior to do the actual development with anything.

Thank you.
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: Change instance of other frame

Post by alys666 »

mxoliveira73 wrote: Thu Jun 13, 2019 11:49 am mainFrame * __mainFrameInstance = new mainFrame(0);

void NewDialog::OnButtonZClick(wxCommandEvent& event){
__mainFrameInstance->Button_mainFrame->SetLabel("lalala");
}
this code compile whitout errors;
but clicking in the ButtonZ, Button_mainFrame don't SetLabel("lalala");
you must somehow register this handler OnButtonZClick, to have him getting events.
put debugger breakpoint at this line...

Code: Select all

	__mainFrameInstance->Button_mainFrame->SetLabel("lalala");
and test if debugger hits this line, if you clicked the button.
ubuntu 20.04, wxWidgets 3.2.1
Post Reply