I have been trying out codelite in my learning of wxWidgets and C++. I was reading about XRC files to store the gui front end, I like the idea of the this as it separates the code and the interface design. I tried to fire up a project on codelite with skeleton code for an XRC project - start a new project for Executable (wxWidgets + XRC Frame). The skeleton code compiles but when it is run it says "cannot load resources from '../gui.xrc'". The file is there and I have not done anything with the project. I am using 3.1.4 build of wxWidgets that I compiled on my machine. Here are the code snippets:
main.h
Code: Select all
#ifndef __MAIN_H__
#define __MAIN_H__
////////////////////////////////////////////////////////////////////////////////
// application class declaration
////////////////////////////////////////////////////////////////////////////////
class MainApp : public wxApp
{
public:
virtual bool OnInit();
};
// declare global static function wxGetApp()
DECLARE_APP(MainApp)
////////////////////////////////////////////////////////////////////////////////
// main application frame declaration
////////////////////////////////////////////////////////////////////////////////
class MainFrame : public wxFrame
{
public:
MainFrame(wxWindow *parent = NULL);
~MainFrame();
private:
void OnCloseFrame(wxCloseEvent& event);
void OnExitClick(wxCommandEvent& event);
};
#endif //__MAIN_H__
Code: Select all
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/xrc/xmlres.h>
#include <wx/image.h>
#include "main.h"
// initialize the application
IMPLEMENT_APP(MainApp);
////////////////////////////////////////////////////////////////////////////////
// application class implementation
////////////////////////////////////////////////////////////////////////////////
bool MainApp::OnInit()
{
if (!wxApp::OnInit())
return false;
wxInitAllImageHandlers();
wxXmlResource::Get()->InitAllHandlers();
if (!wxXmlResource::Get()->Load(wxT("../gui.xrc")))
return false;
SetTopWindow(new MainFrame(NULL));
GetTopWindow()->Show();
// true == enter the main loop
return true;
}
////////////////////////////////////////////////////////////////////////////////
// main application frame implementation
////////////////////////////////////////////////////////////////////////////////
MainFrame::MainFrame(wxWindow* parent)
{
wxXmlResource::Get()->LoadFrame(this, parent, wxT("MainFrame"));
Connect(wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(MainFrame::OnCloseFrame));
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(MainFrame::OnExitClick));
}
MainFrame::~MainFrame()
{
Disconnect(wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(MainFrame::OnCloseFrame));
Disconnect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(MainFrame::OnExitClick));
}
void MainFrame::OnCloseFrame(wxCloseEvent& event)
{
Destroy();
}
void MainFrame::OnExitClick(wxCommandEvent& event)
{
Destroy();
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<resource xmlns="http://www.wxwidgets.org/wxxrc">
<object class="wxFrame" name="MainFrame">
<title>wxMiniApp</title>
<centered>1</centered>
<style>wxDEFAULT_FRAME_STYLE|wxCLOSE_BOX|wxTAB_TRAVERSAL</style>
<object class="wxMenuBar" name="m_menuBar">
<style/>
<object class="wxMenu" name="m_menuFile">
<label>&File</label>
<style/>
<object class="wxMenuItem" name="wxID_EXIT">
<label/>
<accel>
<![CDATA[]]>
</accel>
<help>
<![CDATA[]]>
</help>
</object>
</object>
</object>
<object class="wxStatusBar" name="m_statusBar">
<style/>
<fields>1</fields>
</object>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem" name="boxSizer12">
<flag>wxALL|wxALIGN_CENTER</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<flag>wxALL|wxALIGN_CENTER</flag>
<border>5</border>
<object class="wxStaticText" name="m_staticText">
<label>Testing 123</label>
<style/>
</object>
</object>
</object>
</object>
</object>
</object>
</resource>
Thanks,
MArtyn