Question

1) I've already installed gtk2 with port (port install gtk2)
2) I've compiled my code (using wx) successfully.

When I execute my binary, it doesn't work as I expected. No window shows there.

Below is my simple demo code:

#include <wx/wx.h>

enum
{
    ID_FRAME,
    ID_BTN,
};

class HelloWorldApp : public wxApp
{
public:
    virtual bool OnInit();
private:
    wxButton* button;
};

IMPLEMENT_APP(HelloWorldApp)

bool HelloWorldApp::OnInit()
{
    wxFrame *frame = new wxFrame((wxFrame*) NULL, ID_FRAME, _T("Hello wxWidgets World"));
    frame->CreateStatusBar();
    frame->SetStatusText(_T("Hello World"));
    button = new wxButton((wxFrame *)frame, ID_BTN, _T("123"));
    frame->Show(TRUE);
    SetTopWindow(frame);
    return true;
}
Was it helpful?

Solution

First of all, you really shouldn't using wxGTK under OS X unless you really know what you're doing, the normal thing to do is to use wxOSX.

Second, under OS X applications must be compiled as bundles, look at any of the wxWidgets samples for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top