Main frame collecting Dialog info?

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.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

FlyingIsFun1217 wrote: Anything in particular that you could point me too?
http://www.cplusplus.com/doc/tutorial/classes.html
this website is great for quickly learning new stuff

and, about learning C++ in general:

http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html
this one is great for a beginner to get a more detailed introduction and more thorough explainations

(And my statement "it is not hard" is kinda subjective coming from someone who has been doing OOP for years :P )
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

You rock my world!!!

FlyingIsFun1217 Image
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Ok, I think I have a fair enough grasp on it for now...

Heres my class:

Code: Select all

class NUDInfo
{
public:
	SetNewUserName();
	UpdateListCtrl();
protected:
	wxString ContactNameString;
}

NUDInfo::SetNewUserName()
{
	ContactNameString = ContactNameEntry->GetValue();
}

NUDInfo::UpdateListCtrl()
{
	ContactList->InsertItem(ContactList->GetItemCount(), ContactNameString);
}
So when I want to get the name entered I would use:

Code: Select all

NUDInfo instancename;
instancename.SetNewUserName();
Even with that setting the variable, again, how would I have the Frame know when the dialog was closed so that it can do:

Code: Select all

NUDInfo instancename;
instancename.UpdateListCtrl();
I know there are probably a ton of errors in this code, but I just can't figure this one out :)

Thanks again!
FlyingIsFun1217

---------------------------------EDIT------------------------------

Thinking about it, will it involve setting an event for the dialog to trigger when its closed, and then an event for the frame to do the instancename.UpdateListCtrl?

Thanks!
FlyingIsFun1217
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Anybody?

Thanks!
FlyingIsFun1217
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

N..NN...Nobody? :cry:

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

Post by Auria »

Hey wait a bit i'm not on my computer all day long hitting refresh :P
NUDInfo::SetNewUserName()
{
ContactNameString = ContactNameEntry->GetValue();
}
This is wrong - ContactNameEntry is located in dialog , so frame [or NUDInfo or whatever] does not have access to it directly.

something around these should do (i would still highly recommend you experiment with C++ console programs before trying to do real apps otherwise you will be stuck like that everytime you want to add something more)

try passing the name as parameter:
NUDInfo::SetNewUserName(wxString name)
{
ContactNameString = name;
}


...
in Dialog:

myFrame->SetNewUserName(ContactNameEntry->GetValue())


good luck (but please practice C++ a bit before trying doing wx apps! if you don't you will need to ask help at every step and your program will end up being a buggy mess anyway)

EDIT:i don't want to sound rude, C++ is just not python or some other easy language, you just can't dive in it and learn while programming a real app without it becoming unmaintainable

Even with that setting the variable, again, how would I have the Frame know when the dialog was closed so that it can do


Why not use a method? dialogClosed()

you can also set up an event, but the method is much easier
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Thanks :)

I was just starting to get worried after about 24 hours and no reply. From anybody :P

I will work more with classes and see if I can't get the hang of them before I move on to other things in my app like this :)

Thanks!
FlyingIsFun1217
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Auria wrote:Why not use a method? dialogClosed()
Well, guess I just hadn't heard enough about it. Would it be in this sort of format, under the Main Frame cpp file?:

Code: Select all

void DialogNotFrame::dialogClosed()
{
    NUDInfo instancename;
    instancename.UpdateListCtrl();
}
FlyingIsFun1217 :)
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

FlyingIsFun1217 wrote:
Auria wrote:Why not use a method? dialogClosed()
Well, guess I just hadn't heard enough about it. Would it be in this sort of format, under the Main Frame cpp file?:

Code: Select all

void DialogNotFrame::dialogClosed()
{
    NUDInfo instancename;
    instancename.UpdateListCtrl();
}
FlyingIsFun1217 :)
Well you could place the method in Frame, not Dialog. And in Dialog::closeEvent/okPressed/whatever you called it, call myFrame->dialogClosed() to notify the frame the dialog is done.

But yeah learn more about classes, this is off-topic with wxWidgets and if you had more C++ knowledge this would be obvious to you ;)
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Auria wrote:Well you could place the method in Frame, not Dialog. And in Dialog::closeEvent/okPressed/whatever you called it, call myFrame->dialogClosed() to notify the frame the dialog is done.

But yeah learn more about classes, this is off-topic with wxWidgets and if you had more C++ knowledge this would be obvious to you ;)
Will do both :)
Actually, I'm kinda glad that I understand classes a little better. It'll help QUITE A BIT in the future :D

Thanks again, let me switch over to windows and try it out :)

FlyingIsFun1217
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Ok, trying to compile my simple little class.
Here's what I get:

On this part:

Code: Select all

NUDInfo::SetNewUserName(NewUserNameString)
{
    ContactNameString = NewUserNameString;
}
I just get this error:
error: expected constructor, destructor, or type conversion before '(' token.
FlyingIsFun1217
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

FlyingIsFun1217 wrote:Ok, trying to compile my simple little class.
Here's what I get:

On this part:

Code: Select all

NUDInfo::SetNewUserName(NewUserNameString)
{
    ContactNameString = NewUserNameString;
}
I just get this error:
error: expected constructor, destructor, or type conversion before '(' token.
FlyingIsFun1217
i would need to see more code, but probably because you did not specify a return type. void NUDInfo::SetNewUserName(NewUserNameString) should do it.

EDIT: you also need to specify an argument type. wxString NewUserNameString.

Now PLEASE practice non-wx command-line apps a bit while reading a C++ book. Write useless classes, practice calling them, practice variables, practice methods. If you continue this way i will need to help you at every new step, and i will certainly get tired of it before the program is done

if you want you can even contact me personnaly and i will be happy to help you with any problem you may meet - but it's just a very bad idea to try making wxWidgets app with your current understanding of C++, and especially since you don't even seem to be able to copy examples i give you :P
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Yeah, I am, just trying to multitask :P

Thanks
FlyingIsFun1217
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 »

Auria wrote:i would need to see more code, but probably because you did not specify a return type. void NUDInfo::SetNewUserName(NewUserNameString) should do it.

EDIT: you also need to specify an argument type. wxString NewUserNameString.
It seems the wxString was the only part I was missing, realized that I would be needing that after practicing a bunch ;)

As to the one part that I can't figure out how to fix. I have the following:

Code: Select all

void NUDInfo::UpdateListCtrl(wxString ListCtrlName)
{
    ListCtrlName->InsertItem(ListCtrlName->GetItemCount(), ContactNameString);
}
As you can tell, I want it to update the specified list control with the name collected. I know that what it is trying to do though is insert an item into the wxString, which obviously doesn't work. Should I just convert the wxString ListCtrlName to a char array?

Thanks, you've been extremely helpful!
FlyingIsFun1217 :)
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

From the docs: http://www.wxwidgets.org/manuals/2.8.0/ ... insertitem

long InsertItem(long index, const wxString& label)
Inserts a string item.

It does take a wxString, why are you talking of converting to char* ? I don't really get what's wrong, if you get an error message please post it.

EDIT: Is ListCtrlName a wxString?? You need to append to the wxListCtrl, not to the wxString!! there is no InsertItem method in wxString
Post Reply