wxTextControl problem

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
Reeper
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Feb 09, 2007 12:14 am

wxTextControl problem

Post by Reeper »

Hi i have a GUI that has multipul forms. Each form is a seperate .cc and .h file. On one form a user needs to enter some data to txtbox. When the user clicks a button it will change forms and i would like to be able to send the data to the new form. Eg Form AddUser.cc with txtbox txt_box_1->GetValue() and set a label caption on form User.cc. I hope this makes sense. Cheers for any help.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Eg Form AddUser.cc with txtbox txt_box_1->GetValue()
Err well you explained yourself how to proceed!

Please be more precise on what you don' t know how to do, since you've just explained how it works.
Reeper
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Feb 09, 2007 12:14 am

Post by Reeper »

Ok sorry the form MyFrame3 has the text box on it and i have grabed the text into a variable wxString Name; and on form PicChoice i would like to change a label to have the caption of Name.

But how do i access it from a nother form eg User.cc.

void MyFrame3::BtPics(wxCommandEvent &event)
{
Name = text_ctrl_1->GetValue();
PicChoice* frame_1 = new PicChoice(0, 10, wxT(""));
this->Hide();
frame_1->Show(true);
this->Hide();
}
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

You will need to transfer Name from a class, or let it be accessed - the best way to do it depends a lot on the type of code you make.

If MyFrame3 is the class that calls User/whatever, you could just pass Name as a method argument.

Otherwise you can make MyFrame3 and Use/whatever know each other by sharing pointers or having a common "parent" they both have pointers to. And then it's just a matter of adding GetName/SetName methods so that they can share information.

There are other ways to proceed of course - hope it helps.
Reeper
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Feb 09, 2007 12:14 am

Post by Reeper »

Code: Select all

class MyFrame3: public wxFrame {
public:
    // begin wxGlade: MyFrame3::ids
    // end wxGlade
    MyFrame3(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
	
private:
    // begin wxGlade: MyFrame3::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    // begin wxGlade: MyFrame3::attributes
    wxTextCtrl* text_ctrl_1;
    wxComboBox* combo_box_2;
    wxComboBox* combo_box_1;
    wxButton* button_1;
    wxButton* button_2;
    // end wxGlade

    DECLARE_EVENT_TABLE();

public:
    void TxtName(wxCommandEvent &event); // wxGlade: <event_handler>
    void ComDepart(wxCommandEvent &event); // wxGlade: <event_handler>
    void BtPics(wxCommandEvent &event); // wxGlade: <event_handler>
    void BtBack(wxCommandEvent &event); // wxGlade: <event_handler>
    wxString Name;
}; // wxGlade: end class


#endif // ADDUSER_H

That is the class i have added it in as a string in public. but still cant access it from the other form, I am still new to this so if you could give sampes that would be much appriciated. 

When i try to access it from another form i get 2 errors

AddUser.h:42: error: object missing in reference to
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

(For a complete answer could you provide a minimal working sample? That's almost always the best way to get a quick and complete answer)

Also the error mentions two lcoations:
AddUser.h:42: error: object missing in reference to
Reeper
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Feb 09, 2007 12:14 am

Post by Reeper »

Ok its a lot of files but when you click the button it runs

Code: Select all

void MyFrame3::BtPics(wxCommandEvent &event)
{
	Name = text_ctrl_1->GetValue();
	PicChoice* frame_1 = new PicChoice(0, 10, wxT(""));
	this->Hide();
	frame_1->Show(true);
	this->Hide();
}
This opens another window and closes the one open. and then another button is pushed and opens a new window with the same sorta code. Then a lable on the form that has opend i wanna set to the variable Name.

AddUser.h

Code: Select all

// -*- C++ -*- generated by wxGlade 0.4.1 on Thu Feb  8 15:59:37 2007
#include <wx/string.h>
#include <wx/wx.h>
#include <wx/image.h>
#include <iostream>

using namespace std;
// begin wxGlade: ::dependencies
// end wxGlade

#ifndef ADDUSER_H
#define ADDUSER_H

class MyFrame3: public wxFrame {
public:
    // begin wxGlade: MyFrame3::ids
    // end wxGlade
    MyFrame3(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
	
private:
    // begin wxGlade: MyFrame3::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    // begin wxGlade: MyFrame3::attributes
    wxTextCtrl* text_ctrl_1;
    wxComboBox* combo_box_2;
    wxComboBox* combo_box_1;
    wxButton* button_1;
    wxButton* button_2;
    // end wxGlade

    DECLARE_EVENT_TABLE();

public:
    void TxtName(wxCommandEvent &event); // wxGlade: <event_handler>
    void ComDepart(wxCommandEvent &event); // wxGlade: <event_handler>
    void BtPics(wxCommandEvent &event); // wxGlade: <event_handler>
    void BtBack(wxCommandEvent &event); // wxGlade: <event_handler>
    wxString Name;
}; // wxGlade: end class


#endif // ADDUSER_H
AddUser.cc

Code: Select all

// -*- C++ -*- generated by wxGlade 0.4.1 on Thu Feb  8 15:59:37 2007

#include "AddUser.h"
#include "MainMenu.h"
#include "Button_Add_Pic.h"
#include "UploadPic.h"

MyFrame3::MyFrame3(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
    // begin wxGlade: MyFrame3::MyFrame3
    text_ctrl_1 = new wxTextCtrl(this, -1, wxT("Full Name"));
    const wxString combo_box_2_choices[] = {
        wxT("Select Department"),
        wxT("Accounts"),
        wxT("PayRole"),
        wxT("Human Resorces"),
        wxT("It"),
        wxT("Security"),
        wxT("Special")
    };
    combo_box_2 = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 7, combo_box_2_choices, wxCB_DROPDOWN|wxCB_SORT);
    const wxString combo_box_1_choices[] = {
        wxT("Select Security Level"),
        wxT("1"),
        wxT("2"),
        wxT("3"),
        wxT("4"),
        wxT("5"),
        wxT("6")
    };
    combo_box_1 = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 7, combo_box_1_choices, wxCB_DROPDOWN);
    button_1 = new wxButton(this, 1, wxT("Add Pictures"));
    button_2 = new wxButton(this, 2, wxT("Back"));
    set_properties();
    do_layout();
    // end wxGlade
}


BEGIN_EVENT_TABLE(MyFrame3, wxFrame)
    // begin wxGlade: MyFrame3::event_table
    EVT_TEXT(-1, MyFrame3::TxtName)
    EVT_COMBOBOX(-1, MyFrame3::ComDepart)
    EVT_BUTTON(1, MyFrame3::BtPics)
    EVT_BUTTON(2, MyFrame3::BtBack)
    // end wxGlade
END_EVENT_TABLE();


void MyFrame3::TxtName(wxCommandEvent &event)
{
    event.Skip();
}


void MyFrame3::ComDepart(wxCommandEvent &event)
{
    event.Skip();
}


void MyFrame3::BtPics(wxCommandEvent &event)
{
	Name = text_ctrl_1->GetValue();
	PicChoice* frame_1 = new PicChoice(0, 10, wxT(""));
	this->Hide();
	frame_1->Show(true);
	this->Hide();
}


void MyFrame3::BtBack(wxCommandEvent &event)
{
    MyFrame1* frame_1 = new MyFrame1(0, 10, wxT(""));
    this->Hide();
	frame_1->Show(true);
}


// wxGlade: add MyFrame3 event handlers


void MyFrame3::set_properties()
{
    // begin wxGlade: MyFrame3::set_properties
    SetTitle(wxT("Add User"));
    text_ctrl_1->SetMinSize(wxSize(200, 25));
    combo_box_2->SetMinSize(wxSize(200, 25));
    combo_box_2->SetSelection(0);
    combo_box_1->SetMinSize(wxSize(200, 25));
    combo_box_1->SetSelection(0);
    button_1->SetMinSize(wxSize(200, 30));
    button_2->SetMinSize(wxSize(200, 30));
    // end wxGlade
}


void MyFrame3::do_layout()
{
    // begin wxGlade: MyFrame3::do_layout
    wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    sizer_1->Add(text_ctrl_1, 0, wxALIGN_CENTER_HORIZONTAL|wxADJUST_MINSIZE, 0);
    sizer_1->Add(combo_box_2, 0, wxALIGN_CENTER_HORIZONTAL|wxADJUST_MINSIZE, 0);
    sizer_1->Add(combo_box_1, 0, wxALIGN_CENTER_HORIZONTAL|wxADJUST_MINSIZE, 0);
    sizer_1->Add(button_1, 0, wxALIGN_CENTER_HORIZONTAL|wxADJUST_MINSIZE, 0);
    sizer_1->Add(button_2, 0, wxALIGN_CENTER_HORIZONTAL|wxADJUST_MINSIZE, 0);
    SetAutoLayout(true);
    SetSizer(sizer_1);
    sizer_1->Fit(this);
    sizer_1->SetSizeHints(this);
    Layout();
    Centre();
    // end wxGlade
}
UploadPic.h

Code: Select all

// -*- C++ -*- generated by wxGlade 0.4.1 on Thu Feb  8 18:50:25 2007
#include <wx/wx.h>
#include <wx/image.h>

// begin wxGlade: ::dependencies
// end wxGlade


#ifndef UPLOADPIC_H
#define UPLOADPIC_H

class UploadPicure: public wxFrame {
public:
    // begin wxGlade: UploadPicure::ids
    // end wxGlade

    UploadPicure(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);

private:
    // begin wxGlade: UploadPicure::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    // begin wxGlade: UploadPicure::attributes
    wxStaticText* label_1;
    wxStaticText* label_4;
    wxStaticText* label_2;
    wxStaticText* label_5;
    wxStaticText* label_3;
    wxStaticText* label_6;
    wxPanel* panel_1;
    wxStaticText* label_7;
    wxPanel* panel_2;
    wxListBox* list_box_1;
    wxButton* button_1;
    wxPanel* panel_5;
    wxButton* button_2;
    wxButton* button_3;
    wxPanel* panel_6;
    wxButton* button_4;
    // end wxGlade
    DECLARE_EVENT_TABLE();

public:
    void Ok(wxCommandEvent &event); // wxGlade: <event_handler>
    void AddPic(wxCommandEvent &event); // wxGlade: <event_handler>
    void DelPic(wxCommandEvent &event); // wxGlade: <event_handler>
    void Back(wxCommandEvent &event); // wxGlade: <event_handler>
}; // wxGlade: end class


#endif // UPLOADPIC_H
UploadPic.cc

Code: Select all

// -*- C++ -*- generated by wxGlade 0.4.1 on Thu Feb  8 18:50:25 2007

#include "UploadPic.h"
#include "AddUser.h"

UploadPicure::UploadPicure(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
    // begin wxGlade: UploadPicure::UploadPicure
    label_1 = new wxStaticText(this, -1, wxT("Name:"));
    label_4 = new wxStaticText(this, -1, wxT("label_4"));
    label_2 = new wxStaticText(this, -1, wxT("Department:"));
    label_5 = new wxStaticText(this, -1, wxT("label_5"));
    label_3 = new wxStaticText(this, -1, wxT("Security Level:"));
    label_6 = new wxStaticText(this, -1, wxT("label_6"));
    panel_1 = new wxPanel(this, -1);
    label_7 = new wxStaticText(this, -1, wxT("Picture List"));
    panel_2 = new wxPanel(this, -1);
    const wxString list_box_1_choices[] = {
        
    };
    list_box_1 = new wxListBox(this, -1, wxDefaultPosition, wxDefaultSize, 0, list_box_1_choices, 0);
    button_1 = new wxButton(this, 1, wxT("Ok"));
    panel_5 = new wxPanel(this, -1);
    button_2 = new wxButton(this, 2, wxT("Add Picture"));
    button_3 = new wxButton(this, 3, wxT("Delete Picture"));
    panel_6 = new wxPanel(this, -1);
    button_4 = new wxButton(this, 4, wxT("Back"));

    set_properties();
    do_layout();
    // end wxGlade
}


BEGIN_EVENT_TABLE(UploadPicure, wxFrame)
    // begin wxGlade: UploadPicure::event_table
    EVT_BUTTON(1, UploadPicure::Ok)
    EVT_BUTTON(2, UploadPicure::AddPic)
    EVT_BUTTON(3, UploadPicure::DelPic)
    EVT_BUTTON(4, UploadPicure::Back)
    // end wxGlade
END_EVENT_TABLE();


void UploadPicure::Ok(wxCommandEvent &event)
{
    event.Skip();
}


void UploadPicure::AddPic(wxCommandEvent &event)
{
    event.Skip();
}


void UploadPicure::DelPic(wxCommandEvent &event)
{
    event.Skip();
}


void UploadPicure::Back(wxCommandEvent &event)
{
 	MyFrame3* frame_1 = new MyFrame3(0, 10, wxT(""));
	this->Hide();
	frame_1->Show(true);	
}


// wxGlade: add UploadPicure event handlers


void UploadPicure::set_properties()
{
    // begin wxGlade: UploadPicure::set_properties
    SetTitle(wxT("Upload Pictures"));
    label_4->Enable(false);
    label_4->SetLabel(MyFrame3::Name());
    label_5->Enable(false);
    label_6->Enable(false);
    label_7->SetMinSize(wxSize(93, 18));
    label_7->SetFont(wxFont(11, wxDEFAULT, wxNORMAL, wxBOLD, 0, wxT("")));
    list_box_1->SetMinSize(wxSize(410, 63));
    // end wxGlade
}


void UploadPicure::do_layout()
{
    // begin wxGlade: UploadPicure::do_layout
    wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_5 = new wxBoxSizer(wxHORIZONTAL);
    wxGridSizer* grid_sizer_1 = new wxGridSizer(3, 2, 0, 0);
    grid_sizer_1->Add(label_1, 0, wxADJUST_MINSIZE, 0);
    grid_sizer_1->Add(label_4, 0, wxADJUST_MINSIZE, 0);
    grid_sizer_1->Add(label_2, 0, wxADJUST_MINSIZE, 0);
    grid_sizer_1->Add(label_5, 0, wxADJUST_MINSIZE, 0);
    grid_sizer_1->Add(label_3, 0, wxADJUST_MINSIZE, 0);
    grid_sizer_1->Add(label_6, 0, wxADJUST_MINSIZE, 0);
    sizer_2->Add(grid_sizer_1, 1, wxEXPAND, 0);
    sizer_5->Add(panel_1, 1, wxEXPAND, 0);
    sizer_5->Add(label_7, 0, wxADJUST_MINSIZE, 0);
    sizer_5->Add(panel_2, 1, wxEXPAND, 0);
    sizer_3->Add(sizer_5, 1, wxEXPAND, 0);
    sizer_3->Add(list_box_1, 0, wxADJUST_MINSIZE, 0);
    sizer_4->Add(button_1, 0, wxADJUST_MINSIZE, 0);
    sizer_4->Add(panel_5, 1, wxEXPAND, 0);
    sizer_4->Add(button_2, 0, wxADJUST_MINSIZE, 0);
    sizer_4->Add(button_3, 0, wxADJUST_MINSIZE, 0);
    sizer_4->Add(panel_6, 1, wxEXPAND, 0);
    sizer_4->Add(button_4, 0, wxADJUST_MINSIZE, 0);
    sizer_3->Add(sizer_4, 1, wxEXPAND, 0);
    sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
    sizer_1->Add(sizer_2, 1, wxEXPAND, 0);
    SetAutoLayout(true);
    SetSizer(sizer_1);
    sizer_1->Fit(this);
    sizer_1->SetSizeHints(this);
    Layout();
    Center();
    // end wxGlade
}

If u need the form imbetween i can add it the lines that shove out that error are in this code as well.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Okay at this point it appears obvious to me that you do not master the basics of C++.

Before trying to make such a big graphical app that will all confuse you, i highly suggest that you spend some time writing some test programs on the command-line, with no interface, just to get used to how classes, variables, methods and all that stuff works.

The error is there:
label_4->SetLabel(MyFrame3::Name());
You call Name like it was a static method however it is a member variable.

So either use just Name without () or create a getName method and use GetName();

Second, you use MyFrame3:: instead of somePointer->
That will be harder to fix, you will need UploadPicure to keep a pointer to its parent MyFrame3, or another way to get a pointer to it.

So basically, spend more time learning C++ before diving into that kind of stuff or your program will not get anywhere

good luck :wink: C++ is not a language you can learn while making a [real] app. You need to spend some time learning
Post Reply