WxSmith tutorial: Working with multiple resources Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
FrcEtc
In need of some credit
In need of some credit
Posts: 5
Joined: Wed May 18, 2022 5:47 pm

WxSmith tutorial: Working with multiple resources

Post by FrcEtc »

I am using the wxWmith tutorial at this URL: https://wiki.codeblocks.org/index.php/W ... _resources. When build and run the code and click the buttons, the program fails.

The lines code for the three buttons are:

Code: Select all

void Tutorial_04Frame::OnButton1Click(wxCommandEvent& event)
{
    FirstDialog dialog(this);
    dialog.ShowModal();
}
void Tutorial_04Frame::OnButton2Click(wxCommandEvent& event)
{
    FirstDialog* dlg = new FirstDialog(this);
    dlg->Show();
}
void Tutorial_04Frame::OnButton3Click(wxCommandEvent& event)
{
    FirstFrame* frm = new FirstFrame(this);
    frm->Show();
}
It appears that errant code is in the lines that include "(this)"

The included header files are:

Code: Select all

#include "wx_pch.h"
#include "Tutorial_04Main.h"
#include <wx/msgdlg.h>
#include "FirstDialog.h"
#include "FirstFrame.h"

// (*InternalHeaders(Tutorial_04Frame)
#include <wx/intl.h>
#include <wx/string.h>
//*)
I am using wxWidgets with CODE::BLOCKS 20.03 on Lunux Mint 20.1 Cinnamon

I would appreciate guidance on debugging the code
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxSmith tutorial: Working with multiple resources

Post by doublemax »

When build and run the code and click the buttons, the program fails.
"Fails" is not very helpful. Does it crash or what?

And what makes you think that the issue is related to multiple resources?
Use the source, Luke!
FrcEtc
In need of some credit
In need of some credit
Posts: 5
Joined: Wed May 18, 2022 5:47 pm

Re: WxSmith tutorial: Working with multiple resources

Post by FrcEtc »

Thank you for your help.

As far as the program failing...this is a typical message from the log:

-------------- Run: Debug in Tutorial_04 (compiler: GNU GCC Compiler)---------------

Checking for existence: /home/gshosford/Documents/C++/C++01_Hr_Day/Ch_06/Workshop/Ch06_Exercises/Tutorial_04/bin/Debug/Tutorial_04
Set variable: LD_LIBRARY_PATH=.:/usr/lib/x86_64-linux-gnu:
Executing: /home/gshosford/Documents/C++/C++01_Hr_Day/Ch_06/Workshop/Ch06_Exercises/Tutorial_04/bin/Debug/Tutorial_04 (in /home/gshosford/Documents/C++/C++01_Hr_Day/Ch_06/Workshop/Ch06_Exercises/Tutorial_04/.)
Process terminated with status -11 (0 minute(s), 4 second(s))

It returns "Process terminated with status -11 (0 minute(s), 4 second(s))" when i click the button to execute the code in in any of the three functions.

When I comment out the second line in the first function, as shown below, it returns the same error message.
void Tutorial_04Frame::OnButton1Click(wxCommandEvent& event)
{
FirstDialog dialog(this);
//dialog.ShowModal();
}

However, when I comment out the second line in the second function as shown below:
void Tutorial_04Frame::OnButton2Click(wxCommandEvent& event)
{
FirstDialog* dlg = new FirstDialog(this);
//dlg->Show();
}

it returns:
/home/gshosford/D... line 132 unused variable 'dlg' [Wunused-variable]

However, when I comment out the second line in the third function as shown below:
void Tutorial_04Frame::OnButton3Click(wxCommandEvent& event)
{
FirstFrame* frm = new FirstFrame(this);
//frm->Show();
}

it returns:
Process terminated with status -11 (0 minute(s), 4 second(s))

I am relatively new to C++ and wxWidgets.
I would like to learn to use the debugging tools. However, I have yet to find a resource such as a book or an online tutorial
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxSmith tutorial: Working with multiple resources

Post by doublemax »

Where is the code that connects the event handlers to the button clicks?

Did you see this:
https://wiki.codeblocks.org/index.php/D ... de::Blocks
Use the source, Luke!
FrcEtc
In need of some credit
In need of some credit
Posts: 5
Joined: Wed May 18, 2022 5:47 pm

Re: WxSmith tutorial: Working with multiple resources

Post by FrcEtc »

Thank you for the link to Debugging with Code::Blocks

Here is the rest of the code. ( Please bear in-mind that this code was generated by the version of wxWidgets that is included in the CB IDE:)

/***************************************************************
* Name: Tutorial_04Main.cpp
* Purpose: Code for Application Frame
* Author: g.s.hosford ()
* Created: 2022-05-17
* Copyright: g.s.hosford ()
* License:
**************************************************************/

#include "wx_pch.h"
#include "Tutorial_04Main.h"
#include <wx/msgdlg.h>
#include "FirstDialog.h"
#include "FirstFrame.h"

//(*InternalHeaders(Tutorial_04Frame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);

if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}

return wxbuild;
}

//(*IdInit(Tutorial_04Frame)
const long Tutorial_04Frame::ID_BUTTON1 = wxNewId();
const long Tutorial_04Frame::ID_BUTTON2 = wxNewId();
const long Tutorial_04Frame::ID_BUTTON3 = wxNewId();
const long Tutorial_04Frame::idMenuQuit = wxNewId();
const long Tutorial_04Frame::idMenuAbout = wxNewId();
const long Tutorial_04Frame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(Tutorial_04Frame,wxFrame)
//(*EventTable(Tutorial_04Frame)
//*)
END_EVENT_TABLE()

Tutorial_04Frame::Tutorial_04Frame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(Tutorial_04Frame)
wxBoxSizer* BoxSizer1;
wxMenu* Menu1;
wxMenu* Menu2;
wxMenuBar* MenuBar1;
wxMenuItem* MenuItem1;
wxMenuItem* MenuItem2;

Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
Button1 = new wxButton(this, ID_BUTTON1, _("Show Modal Dialog"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer1->Add(Button1, 1, wxALL|wxEXPAND, 5);
Button2 = new wxButton(this, ID_BUTTON2, _("Add new dialog"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button3 = new wxButton(this, ID_BUTTON3, _("Add new frame"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
BoxSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);

Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Tutorial_04Frame::OnButton1Click);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Tutorial_04Frame::OnButton2Click);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Tutorial_04Frame::OnButton3Click);
Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Tutorial_04Frame::OnQuit);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Tutorial_04Frame::OnAbout);
//*)
}

Tutorial_04Frame::~Tutorial_04Frame()
{
//(*Destroy(Tutorial_04Frame)
//*)
}

void Tutorial_04Frame::OnQuit(wxCommandEvent& event)
{
Close();
}

void Tutorial_04Frame::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}

void Tutorial_04Frame::OnButton1Click(wxCommandEvent& event)
{
FirstDialog dialog(this);
dialog.ShowModal();
}

void Tutorial_04Frame::OnButton2Click(wxCommandEvent& event)
{
FirstDialog* dlg = new FirstDialog(this);
dlg->Show();
}

void Tutorial_04Frame::OnButton3Click(wxCommandEvent& event)
{
FirstFrame* frm = new FirstFrame(this);
frm->Show();
}
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxSmith tutorial: Working with multiple resources

Post by doublemax »

I can't spot anything wrong. Can you put all source files into a zip and attach it to a post?
Use the source, Luke!
FrcEtc
In need of some credit
In need of some credit
Posts: 5
Joined: Wed May 18, 2022 5:47 pm

Re: WxSmith tutorial: Working with multiple resources

Post by FrcEtc »

Thanks again for your help.
I have attached the zip forlder.
Attachments
Tutorial_04.zip
(13.97 KiB) Downloaded 35 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxSmith tutorial: Working with multiple resources

Post by doublemax »

FrcEtc wrote: Fri May 20, 2022 6:20 pm Thanks again for your help.
I have attached the zip forlder.
The auto-generated code is just wrong. I'm not sure if Code::Blocks or wxSmith is to blame, but if you're using the latest version of those, it's time to find a new IDE.

If you want to fix the code, even if it's just to see it run once:

In FirstDialog.cpp comment out this line:

Code: Select all

SetSizer(StaticBoxSizer1);
In FirstFrame.cpp it's the same issue, comment out this line:

Code: Select all

SetSizer(FlexGridSizer1);
BTW: If you had run a debug version of the project, you would have gotten an assert message that exactly describes the problem.

Maybe you should look into CodeLite https://codelite.org/
I haven't used it myself, but heard good things about it.
Use the source, Luke!
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: WxSmith tutorial: Working with multiple resources

Post by Rohit Agarwal »

I have been using CodeLite on Linux Ubuntu after switching from Code::Blocks.
I can vouch for it.
FrcEtc
In need of some credit
In need of some credit
Posts: 5
Joined: Wed May 18, 2022 5:47 pm

Re: WxSmith tutorial: Working with multiple resources

Post by FrcEtc »

@doublemax Thank you so very much for your assistance and pinpointing the bug. I will try CoteLite

@Rohit thank you for endorsing CodeLite.

Cheers!
Post Reply