Re: Parent <--> Child and header files
- From: Mateusz 'vArDo' Bilinski <vardo fr pl>
- To: gtkmm-list gnome org
- Subject: Re: Parent <--> Child and header files
- Date: Sun, 21 Nov 2004 11:38:21 +0100
Dnia 20-11-2004, sob o godzinie 22:42 +0100, B.Hakvoort napisał(a):
> Did i mention there's an example in the gtkmm tarball ?
>
> Good luck, and believe me, its easy :)
I solved the problem in my way :D (but I'll try yours, although I still
don't know how can I get pointers to object methods if I don't know a
class prototype ;/).
THE QUESTIONS ARE AT THE BOTTOM, so don't hesitate to go there firstly.
So here's what I created:
<src file="maintoolbar.hh">
#include <gtkmm/toolbar.h>
namespace RLC
{
class CMainWindow; // THIS WAS THE CASE - to do this instead
// of including mainwindow.hh. How could
// I be so stupid?? ;/
class CMainToolbar : public Gtk::Toolbar
{
public:
CMainToolbar();
~CMainToolbar();
void setParent(RLC::CMainWindow* parent);
protected:
void on_toolbar_button_solve();
RLC::CMainWindow* m_parent;
};
}
</src>
<src file "maintoolbar.cc">
#include "maintoolbar.hh"
#include <gtkmm/stock.h>
#include <gtkmm/separatortoolitem.h>
#include "mainwindow.hh" // AND INCLUDE file later here.
using namespace RLC;
CMainToolbar::CMainToolbar()
{
// HERE GOES THE STUFF CONNECTED WITH TOOLBAR BUTTONS.
// Parent pointer initialization
m_parent = 0; // HERE THE MAIN PROBLEM
}
CMainToolbar::~CMainToolbar()
{
//delete m_parent; // HERE THE SECOND MAIN PROBLEM
}
void CMainToolbar::on_toolbar_button_solve()
{
m_parent->m_MainStatusbar_Bottom.push("Solving");
}
void CMainToolbar::setParent(CMainWindow* parent)
{
m_parent = parent;
}
</src>
In CMainWindow I've got CMainToolbar decalared as friend and
'main_toolbar.setParent(this)' called in mainwindow constructor, so
what's above works fine, and I got "Solving" text in the statusbar at
the bootom.
And know what's wrong...
Firstly, when I use
m_parent = new CMainWindow;
instead of:
m_parent = 0;
the program stops at this moment and won't give a go forward. After
interrupting it I've got no output.
Secondly, when i uncomment the line:
//delete m_parent;
At the end of execution of program I've got memory protection violation
error. Is this because gtkmm handles destroyin all pointers to the
classed that inherits from gtkmm classes??
Thanks for the anwsers in advance.
vArDo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]