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
Knows some wx things
Knows some wx things
Posts: 43
Joined: Sun May 05, 2019 7:12 am

Change instance of other frame

Post by mxoliveira73 » Thu Jun 13, 2019 3:10 am

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
I live to help wx-kind
I live to help wx-kind
Posts: 156
Joined: Tue Oct 18, 2016 2:31 pm

Re: Change instance of other frame

Post by alys666 » Thu Jun 13, 2019 5:01 am

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 16.04, wxWidgets 3.0.4

mxoliveira73
Knows some wx things
Knows some wx things
Posts: 43
Joined: Sun May 05, 2019 7:12 am

Re: Change instance of other frame

Post by mxoliveira73 » 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");

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Change instance of other frame

Post by evstevemd » Thu Jun 13, 2019 12:31 pm

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?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3278
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change instance of other frame

Post by ONEEYEMAN » Thu Jun 13, 2019 2:49 pm

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
I live to help wx-kind
I live to help wx-kind
Posts: 156
Joined: Tue Oct 18, 2016 2:31 pm

Re: Change instance of other frame

Post by alys666 » Fri Jun 14, 2019 5:27 am

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 16.04, wxWidgets 3.0.4

Post Reply