user1692950
user1692950

Reputation: 13

cant get a pointer to wxwidget object, using wxsmith

straight to the point: Im learning wxsmith and wxwidgets toolkit, i created some basic GUI containing one button and 2 static text fields. GUI is compilling ok so far. My frame name is proba2Frame, then im adding my own function which is not a member of any class but i declared in header file for proba2Frame that my function is a friend. Below is code of my function:

   wxStaticText * dawajpointera()
    {
    wxStaticText * text;
    text = proba2Frame.wxStaticText.StaticText1;
    return text;
    }

im getting error:

expected primary-expression before ‘.’ token

What exactly im doing wrong and how to get a pointer StaticText in case my solution is completely wrong ?

Thank You in advance

Upvotes: 1

Views: 248

Answers (2)

vinnydiehl
vinnydiehl

Reputation: 1704

You make it sound like proba2Frame is the name of a class inheriting wxFrame?

If so, you're haveing problems because you haven't created an instance of proba2Frame, and you're trying to access a part of it that hasn't been constructed. Your main frame class is simply a template for your GUI, not the GUI itself.

The best way to go about it would probably be to take an instance of proba2Frame as a parameter-

wxStaticText* dawajpointera(proba2Frame *frame)
{
    return frame->StaticText1;
}

Of course, that function itself was a bit pointless, but I'll assume that you're going to do something more involved with the pointer afterwards, and want it set to a pointer named text within the function for the sake of brevity.

void func(proba2Frame *frame)
{
    wxStaticText *text = frame->StaticText1;
    // Do something with text
}

If you're doing this, though, please consider making the function a method of proba2Frame.

Upvotes: 2

ravenspoint
ravenspoint

Reputation: 20596

wxStaticText is the name of a wxWidgets class. You should not be naming attributes of your frame 'wxStaticText'. Despite the code you have posted, I doubt that you have really done such a terrible thing. What you probably meant to write, I would guess, is:

text =  proba2Frame.StaticText1;

I am guessing that the name of the attribute is StaticText1, a pointer to an instance of the wxStaticText class.

Upvotes: 0

Related Questions