Page 1 of 1

WxWidgets App with multiples windows

Posted: Wed May 15, 2019 1:48 pm
by steph291
Hi everyone,
I'm new to C++ and RAD tools (wxSmith within CodeBlocks)

So far it's working and fun BUT today is scratchingHead day...

I have a main window that call another window.

On event (a double click)
do your stuff and catch another event in the main window
which is OnTreeCtrl1ItemActivated(wxTreeEvent& event)
a treectrl widget...

But when the second window occur, I cannot access
variables from the first part (wxString test1 or test2)

The reason is not public?, Global?

code following :

Code: Select all

void test12052019Frame::OnButton1Click(wxCommandEvent& event)
    wxString test1 = "";
    wxString test2 = "";

    test1 = TextCtrl1->GetValue();
    test2 = TextCtrl2->GetValue();

    // compare/parse userid/password
    // Access ERP system and get credential schema
    // build the treeview

    if(test1 == "titou" && test2 == "123123"){
    // todo auth. against Mysql
        wxMessageBox("You're in !!\n");
        wxMessageBox("You're out !!\nWrong userid/password");

void test12052019Frame::OnTreeCtrl1ItemActivated(wxTreeEvent& event)
    //TreeCtrl1 is my tree
    //when I click on any option of my tree
    //it activates a wxMessageBox with the label
    //of the option selected...
    //just let go your imagination :)

    NewFrameActivities *mynewwindow = new NewFrameActivities(this);

    wxString thelabel;
    wxTreeItemId test3;

    test3 = TreeCtrl1->GetSelection();
    thelabel = TreeCtrl1->GetItemText(test3);



//    mynewwindow->StaticBox1->SetLabel(); // I would like to SetLabel to variable in the
//    first module/event like : test1, the name of the user



wtach the video on youtube and you'll get the picture :)

thanks and regards

Re: WxWidgets App with multiples windows

Posted: Wed May 15, 2019 2:07 pm
by catalin
Is the value held in test3 valid? You should always get a valid tree item id using event.GetItem().

Re: WxWidgets App with multiples windows

Posted: Wed May 15, 2019 4:10 pm
by doublemax
test1 and test2 are local variables in the method "OnButton1Click", you can't access them from anywhere else. You could turn them into member variables of "test12052019Frame", but i would just use TextCtrl1->GetValue() again.