User forums > General (but related to Code::Blocks)
wxWidgets XML resource files
(1/1)
sethjackson:
I'm trying to load a menu from an .xrc file. Unfortuately I keep getting errors.
main.cpp
--- Code: ---#include <wx/xrc/xmlres.h>
#include "main.h"
int idFileQuit = XRCID("idFileQuit");
int idHelpAbout = XRCID("idHelpAbout");
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(idFileQuit, MainFrame::OnQuit)
EVT_MENU(idHelpAbout, MainFrame::OnAbout)
END_EVENT_TABLE()
MainFrame::MainFrame(wxFrame *frame, const wxString& title,
int xpos, int ypos, int width, int height)
: wxFrame(frame, -1, title, wxPoint(xpos, ypos), wxSize(width, height))
{
wxXmlResource::Get()->InitAllHandlers();
wxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));
CreateMenubar();
}
MainFrame::~MainFrame()
{
}
bool MainFrame::CreateMenubar()
{
wxMenuBar* mbar = 0L;
wxXmlResource *myres = wxXmlResource::Get();
myres->Load(_T("/resources.zip#zip:main_menu.xrc"));
myres->LoadMenuBar(0L, _T("main_menu_bar"));
SetMenuBar(mbar);
return true;
}
void MainFrame::OnQuit(wxCommandEvent& event)
{
Close(true);
}
void MainFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox(_("wxWidgets Example"), _("Welcome to..."));
}
--- End code ---
main_menu.xrc
--- Code: ---<?xml version="1.0"?>
<resource>
<object class="wxMenuBar" name="main_menu_bar">
<object class="wxMenu" name="file_menu">
<label>&File</label>
<object class="wxMenuItem" name="idFileExit">
<label>&Quit</label>
<accel>Ctrl-Q</accel>
<help>Quit wxWidgets Example</help>
</object>
</object>
<object class="wxMenu" name="help_men">
<label>&Help</label>
<object class="wxMenuItem" name="wxID_ABOUT">
<label>&About...</label>
<help>About wxWidgets Example</help>
</object>
</object>
</object>
</resource>
--- End code ---
So wxWidgets tells me "XRC resource 'main_menu_bar' (class 'wxMenuBar') not found!"
It gives me a nice little error box I click on details and it says "can't load resources from file '"/resources.zip#zip:main_menu.xrc' (time)"
It gives me an option to save to a log and here is the log.
16:05:59: Cannot load resources from file '/resources.zip#zip:main_menu.xrc'.
16:05:59: Cannot load resources from file '/resources.zip#zip:main_menu.xrc'.
16:05:59: XRC resource 'main_menu_bar' (class 'wxMenuBar') not found!
What am I doing wrong? This is totally new to me, I have never used wxWidgets before.
mandrav:
--- Quote ---wxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));
--- End quote ---
You should change this to relative path, e.g.
--- Code: ---wxXmlResource::Get()->Load(_T("resources.zip#zip*.xrc"));
--- End code ---
(notice it's "resources" not "/resources")
sethjackson:
--- Quote from: mandrav on September 29, 2005, 11:16:55 pm ---
--- Quote ---wxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));
--- End quote ---
You should change this to relative path, e.g.
--- Code: ---wxXmlResource::Get()->Load(_T("resources.zip#zip*.xrc"));
--- End code ---
(notice it's "resources" not "/resources")
--- End quote ---
I did that still nothing. I keep getting the same error.
Maybe something else is wrong?
Urxae:
Did you initialize the zip file handler? If not, wxWidgets has no idea how to get the stuff in a zip file.
On application startup, call
--- Code: ---wxFileSystem::AddHandler(new wxZipFSHandler);
--- End code ---
(don't forget to include <wx/filesys.h> and <wx/fs_zip.h>)
HTH
sethjackson:
--- Quote from: Urxae on September 30, 2005, 12:39:15 am ---Did you initialize the zip file handler? If not, wxWidgets has no idea how to get the stuff in a zip file.
On application startup, call
--- Code: ---wxFileSystem::AddHandler(new wxZipFSHandler);
--- End code ---
(don't forget to include <wx/filesys.h> and <wx/fs_zip.h>)
HTH
--- End quote ---
Thanks Urxae that makes sense. Duh :oops:
EDIT:
Ok so I change
--- Code: ---myres->LoadMenuBar(0L, _T("main_menu_bar"));
--- End code ---
to
--- Code: ---mbar = myres->LoadMenuBar(0L, _T("main_menu_bar"));
--- End code ---
and I fixed the .xrc file to have the right XRCID's
:oops: :roll:
Sometimes I need to think before I dive right in to coding.
Navigation
[0] Message Index
Go to full version