Calling Non-Wx Object

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
jana
Earned a small fee
Earned a small fee
Posts: 13
Joined: Mon Dec 14, 2020 1:52 am

Calling Non-Wx Object

Post by jana »

Windows 10, Visual Studio 2019, WxWidgets 3.1.5

I'm very new to WxWidgets. I need to use some non-Wx, non-gui classes of my own, to do some processing.

I'm not sure the best way to do it. Clicking a button starts the processing, so I declared my non-Wx class in the header file for the button's frame. The frame has my object as a data member. Then in the OnQuit handler, I call the object's method. (The OnQuit isn't significant. I'm just borrowing the code from one of the simple tutorials to test this.)

Code: Select all

class NonWxObject
{
public:
    void say_hello();
};
 
class Button : public wxFrame
{
private:
    NonWxObject thing;
public:
    Button(const wxString& title);
 
    void OnQuit(wxCommandEvent& event);
};
Is that the best way to do this, calling my method from one of the handlers? Would it be better to declare my classes in global scope?

By the way, I've searched for info on scope in WxWidgets and haven't found any yet. Is WxWidgets scope different than C++?

I've posted all the code here:
https://pastebin.com/pknZ5Fh8

I'd be grateful for any suggestions.
Act boldly, and unforseen forces will come to your aid. --- (has been attributed to more than one person)
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Calling Non-Wx Object

Post by doublemax »

In general the way you did it is just fine. The only issue could arise if the method you call takes a long time to execute, because that would block the GUI. In that case you should move the processing to a different thread.
By the way, I've searched for info on scope in WxWidgets and haven't found any yet. Is WxWidgets scope different than C++?
wxWidgets does not have its own namespace, if that's what you mean.
Use the source, Luke!
Post Reply