XRCCTRL expression must have class type Topic is solved

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
AnFer
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Nov 19, 2021 11:16 pm

XRCCTRL expression must have class type

Post by AnFer »

Hey everyone!

I've been trying to dev with wxWidgets. This afternoon I started playing with wxFormBuilder and XRC files.
I can load frames just fine, but when I start trying to use XRCCTRL to load a button and bind to an event like the tutorial shows I get an error:
expression must have class type
.

Code is

Code: Select all

#include "cApp.h"
#include "wx/xrc/xmlres.h"

wxIMPLEMENT_APP(cApp);

bool cApp::OnInit()
{
    //m_frame1 = new cMain();
    //m_frame1->Show();
   
    wxXmlResource::Get()->InitAllHandlers();
    wxXmlResource::Get()->Load("ressources/noname.xrc");

    wxFrame* MainFrame = wxXmlResource::Get()->LoadFrame(NULL, "MyFrame3");
    if (!MainFrame) {
        wxLogError("Failed to load the main frame from the resources.");
        return false;
    }
    XRCCTRL(MainFrame, "clickme_btn", wxButton)->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
        wxCommandEventHandler(MyClass::OnClickme), this, XRCID("clickme_btn"));

    MainFrame->Show();

    return true;
}
I spent a few hours trying to find help on the web and expanding the Macro to see if I could tinker with the original function, but with no success. So yeah, please help 😂

Thanks in advance!

edit: Adding the error in the body of the post.
Last edited by AnFer on Sat Nov 20, 2021 11:24 am, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: XRCCTRL expression must have class type

Post by doublemax »

What's the error message and which tutorial are you referring to?

The first parameter to XRCCTRL is a reference, not a pointer. So try this:

Code: Select all

XRCCTRL(*MainFrame, "clickme_btn", wxButton)
Use the source, Luke!
AnFer
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Nov 19, 2021 11:16 pm

Re: XRCCTRL expression must have class type

Post by AnFer »

Ok thank you, I feel like an idiot.

The error was "expression must have class type"

And I meant the wxWidgets about XRC that they have in the doc: https://docs.wxwidgets.org/3.0/overview_xrc.html

It was indeed me forgetting to deref my Frame, that fixed this error.
But now I have a new error. I'll try to fix it myself first, but if I fail would it be better to ask on this thread or to make a new one? I don't wanna flood but I don't wanna make a thread hard to read for future users.

Thanks again :)
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: XRCCTRL expression must have class type

Post by doublemax »

AnFer wrote: Sat Nov 20, 2021 10:16 am But now I have a new error. I'll try to fix it myself first, but if I fail would it be better to ask on this thread or to make a new one? I don't wanna flood but I don't wanna make a thread hard to read for future users.
If it's related to the previous question, post it here. Otherwise open a new thread.
Use the source, Luke!
AnFer
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Nov 19, 2021 11:16 pm

Re: XRCCTRL expression must have class type

Post by AnFer »

Well, it's the same line of code but different bug and even different function. Let's call it fixed and I'll make a new post later.

Thanks again !
Post Reply