Re: Please help (core dump)

2020-07-28 Thread aitor

Hi,

On 27/7/20 14:00, Carlo Wood  wrote:

Hi aitor,

thank you so much for your examples!
I will definitely study them in depth as soon as I get
my current problem resolved of how to add a 'Mode' to
my menu having a separate Gtk::Builder (aka, how to
combine multiple Gtk::Builder objects into a single
menu). Or, alternatively, I could have just a single
Gtk::Builder object, but then I still need to be
able to somehow add a Gio::SimpleActionGroup to my
menu.

It seems that your approach is entirely different:
you have a MenuBar class that deals with everything
related to the menu. From an object oriented point
of view that makes a lot of sense. You're not using
Gtk::Builder at all, but - instead of using an xml
string - hardcode the menu into the constructor of
myMenuBar.



Yes, Gtk::Builder is cool, but the other point of view simplifies 
dynamic changes because
you can define an iterator which can be used for the addition/removal of 
the items in the

menu.



For some reason you're passing `*this` to every
sigc::mem_fun - aka*all*  `on_menu_*` menu callbacks
are member functions of myMenuBar. I'd prefer it
if I could use callbacks that are member functions
of several different objects (namely those that
they operate on). I suppose I can do that by passing
a pointer to all those objects to the constructor
of myMenuBar. Currently you pass only a WindowMain*,
for the on_menu_mode_quit method.

Why are you using the construct of passing this WindowMain*
as an argument to myMenuBar::on_menu_mode_quit?
Wouldn't it be possible, and make more sense, to do:

 m_QuitItem->signal_activate().connect (
 sigc::mem_fun(*caller, ::on_menu_mode_quit)
 );

?



The sort answer: Yes, you are write! It makes more sense in the other 
way around, so i left the

callbackas follows:

m_QuitItem->signal_activate().connect (
            sigc::mem_fun(*caller, ::hide)
);

Indeed, i was doing something similar in the callback of the status icon 
of my new
network manager. I still didn't finish it, but shortly i'll share the 
code here in the mailing list.

Anyway, I can give you a link to the backend so far:

https://git.devuan.org/aitor_czr/libnetaid

Thanks for your constructive correctness :)

Aitor.





___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-27 Thread Kjell Ahlstedt via gtkmm-list

On 2020-07-27 09:40, Carlo Wood wrote:

Is there an example somewhere that shows how I can combine the
`void on_menu_mode_*()` member functions of a widget that is not
derived (indirectly) from Gio::ActionMap to the menu of the window
that this widgets belongs to?

Thanks,
Carlo Wood


Look at 
https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/gtkmm-3-24/examples/book/menus_and_toolbars/examplewindow.cc


I think that's what you can do. Create a Gio::SimpleActionGroup. Add 
your actions to it. Insert it in your widget with Gtk::Widget's 
insert_action_group() method. In the call to insert_action_group() you 
choose what prefix to use in the ui file.


___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-27 Thread Carlo Wood
On Sun, 26 Jul 2020 20:22:43 +0100
Daniel Boles via gtkmm-list  wrote:

> On Sun, 26 Jul 2020, 20:21 Carlo Wood,  wrote:
> 
> >
> > I'm not sure what you mean with doing
> >
> > LinuxChessboardWidget(..) : Glib::ObjectBase("myWidgetClass")
> >
> > since Glib::ObjectBase is a base class of Gio::ActionMap,
> > I can't call that from LinuxChessboardWidget no?
> >  
> 
> yes, you can: research "virtual base classes"

I don't have to research that :p. I realized that this is possible
when Glib::ObjectBase is a virtual base class; that is why I looked
on https://developer.gnome.org/glibmm/stable/classGio_1_1ActionMap.html

and since there I saw no indication whatsoever that ObjectBase would
be a virtual base class, I concluded it wasn't :/.

I hope my other questions can be answered too, since Kjell said
that deriving from Gio::ActionMap was very unusual and apparently
not the route I should take.

Is there an example somewhere that shows how I can combine the
`void on_menu_mode_*()` member functions of a widget that is not
derived (indirectly) from Gio::ActionMap to the menu of the window
that this widgets belongs to?

Thanks,
Carlo Wood

___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-26 Thread Daniel Boles via gtkmm-list
On Sun, 26 Jul 2020, 20:21 Carlo Wood,  wrote:

>
> I'm not sure what you mean with doing
>
> LinuxChessboardWidget(..) : Glib::ObjectBase("myWidgetClass")
>
> since Glib::ObjectBase is a base class of Gio::ActionMap,
> I can't call that from LinuxChessboardWidget no?
>

yes, you can: research "virtual base classes"
___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-26 Thread Carlo Wood
Hi Kjell,

thank you so much for helping me out!

I'm not sure what you mean with doing

LinuxChessboardWidget(..) : Glib::ObjectBase("myWidgetClass")

since Glib::ObjectBase is a base class of Gio::ActionMap,
I can't call that from LinuxChessboardWidget no?

What I have is the following:

class LinuxChessApplication : public Gtk::Application
{
...
  void on_menu_file_exit();

Where 'Exit' is not related to a single window, but is application
wide (it closes all windows and exits the application).
I add this with add_action to Gtk::Application.

Then I have:

class LinuxChessWindow : public Gtk::ApplicationWindow
{
...
  void on_menu_file_load();
  void on_menu_file_save();
  void on_menu_game_new();
  void on_menu_game_clear();
  void on_menu_game_export();
  void on_menu_game_undo();
  void on_menu_game_flip();
  void on_menu_mode_editposition();
  void on_menu_mode_editgame();

These are added, using add_action, to Gtk::ApplicationWindow.

So, I am using what you said. But, then I have:

class LinuxChessboardWidget : public cwmm::ChessPositionWidget
{
...
  void on_menu_mode_showcandidates();
  void on_menu_mode_showreachables();
  void on_menu_mode_showattacked();
  void on_menu_mode_showdefendables();
  void on_menu_mode_showdefended_black();
  void on_menu_mode_showdefended_white();
  void on_menu_mode_showmoves();
  void on_menu_mode_placepieces();

It is possible, though silly imho, to add those member funtions to
LinuxChessWindow (all those would do is call the member functions of
its LinuxChessboardWidget). So, I rather register these directly.

I couldn't think of another way than to derive LinuxChessboardWidget
from Gio::ActionMap, like Gtk::Application and Gtk::ApplicationWindow.

Should I add a Gio::SimpleActionGroup to LinuxChessboardWidget instead
and add them to that? If I do that, then how can get this
Gio::SimpleActionGroup to be used for my menu? And under what name
would do I have to refer to them in the `ui_info` xml string that
I use for my Gtk::Builder? Or should I use a separate Gtk::Builder?

With 'name' I mean that the menu entries that are added to
Gtk::Application are refered to as "app.*" and those that are
added to Gtk::ApplicationWindow are refered to as "win.*".
I'd like it when the methods of LinuxChessboardWidget can be
refered to as -say- "chessboard.*".


On Sun, 26 Jul 2020 11:06:53 +0200
Kjell Ahlstedt  wrote:

> Gio::ActionMap is an interface. That's why its constructor is
> protected. An interface can't be instantiated by itself. It must be
> implemented by a class which can be instantiated. If you really must
> implement Gio::ActionMap in your class (which I doubt), there is one
> or (probably) two errors.
> 
> First, interfaces must come before the widget class in the list of
> base classes.
> 
> class LinuxChessboardWidget : public Gio::ActionMap, public
> cwmm::ChessPositionWidget
> 
> This is opposite to what's done in gtkmm's classes that wrap gtk
> classes.
> 
> Second, your constructor must call a special Glib::ObjectBase
> constructor that registers your class with its own GType in glib's
> GType system. For instance
> 
> LinuxChessboardWidget(..) : Glib::ObjectBase("myWidgetClass")
> . // Or whatever you want to call it.
> 
> This is an unusual way of using Gio::ActionMap. I don't know if these
> are the only necessary changes. Much more common is to use one of the
> classes that already implement Gio::ActionMap:
> Gio::SimpleActionGroup, Gtk::Application (via Gio::Application) or
> Gtk::ApplicationWindow.
> 

___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-26 Thread aitor

Hi Carlo,

On 25/7/20 15:35, Carlo Wood wrote:

Hi Aitor,

is this gtkmm3? For example, Gtk::VBox is deprecated,
I'm using Gtk::Grid.



Yes, it is. Have a look at the "pkg_check_modules" in the configuration 
of CMake. I'm using the deprecated VBox because this
code is taken froma network manager project, which i'd like to be 
compatible with goth gtkmm-2.24 and gtkmm-3.24.




Currently my application just core dumps:(.
The backtrace is:

Thread 1 "tstcpp" received signal SIGSEGV, Segmentation fault.
0x76bc29c6 in g_action_map_add_action () from /usr/lib/libgio-2.0.so.0
(gdb) bt
#0  0x76bc29c6 in g_action_map_add_action () at /usr/lib/libgio-2.0.so.0
#1  0x778cc541 in Gio::ActionMap::add_action(Glib::ustring const&) () 
at /usr/lib/libgiomm-2.4.so.1
#2  0x778cc65e in Gio::ActionMap::add_action(Glib::ustring const&, 
sigc::slot const&) ()
 at /usr/lib/libgiomm-2.4.so.1
#3  0x55573871 in LinuxChessboardWidget::LinuxChessboardWidget(Gtk::Window*, 
Glib::RefPtr) (this=
 0x563bd928, drawable=0x563bd8a0, promotion=..., __in_chrg=, __vtt_parm=)
 at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessboardWidget.cxx:164
#4  0x5557b68b in LinuxChessWindow::LinuxChessWindow() (this=0x563bd8a0, 
__in_chrg=, __vtt_parm=)
 at /home/carlo/projects/cwchessboard/cwchessboard/LinuxChessWindow.cxx:4
#5  0x5556e473 in LinuxChessApplication::create_window() 
(this=0x555f6230) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessApplication.cxx:160
#6  0x5556e3ed in LinuxChessApplication::on_activate() 
(this=0x555f6230) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessApplication.cxx:155
#7  0x778bbc2c in 
Gio::Application_Class::activate_callback(_GApplication*) () at 
/usr/lib/libgiomm-2.4.so.1
#8  0x7694480a in g_signal_emit_valist () at 
/usr/lib/libgobject-2.0.so.0
#9  0x76944980 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#10 0x76bbea89 in  () at /usr/lib/libgio-2.0.so.0
#11 0x778bba8a in Gio::Application::local_command_line_vfunc(char**&, 
int&) () at /usr/lib/libgiomm-2.4.so.1
#12 0x778bbe51 in 
Gio::Application_Class::local_command_line_vfunc_callback(_GApplication*, 
char***, int*) () at /usr/lib/libgiomm-2.4.so.1
#13 0x76bbec0a in g_application_run () at /usr/lib/libgio-2.0.so.0
#14 0x5557a928 in main(int, char**) (argc=1, argv=0x7fffd448) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChess.cxx:14

Frame #3 (the first that is my code) is:

#3  0x55573871 in LinuxChessboardWidget::LinuxChessboardWidget(this=0x563bd928, 
drawable=0x563bd8a0, promotion=...,__in_chrg=, 
__vtt_parm=)
 at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessboardWidget.cxx:164
164   add_action("ModeShowCandidates", sigc::mem_fun(*this, 
::on_menu_mode_showcandidates));


Why would this core dump??

LinuxChessboardWidget is defined as:

class LinuxChessboardWidget : public cwmm::ChessPositionWidget, public 
Gio::ActionMap
{
   ...

I have to derive from Gio::ActionMap because its constructor is protected.
The call to `add_action` above is to that class.

Can someone tell me what I'm doing wrong?



Mmm..., i don't know, but this issue might be related with some missing 
arguments in your defined signal/slot.


BTW, i uploaded my third examples including an icon factory for the 
customized icons of the second part of the menu bar:


https://www.gnuinos.org/Gtkmm Examples/Example_3/screenshot.png 



Cheers,

Aitor.


___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-26 Thread Kjell Ahlstedt via gtkmm-list

On 2020-07-25 17:35, Carlo Wood wrote:

Why would this core dump??

LinuxChessboardWidget is defined as:

class LinuxChessboardWidget : public cwmm::ChessPositionWidget, public 
Gio::ActionMap
{
   ...

I have to derive from Gio::ActionMap because its constructor is protected.
The call to `add_action` above is to that class.

Can someone tell me what I'm doing wrong?

Carlo

Gio::ActionMap is an interface. That's why its constructor is protected. 
An interface can't be instantiated by itself. It must be implemented by 
a class which can be instantiated. If you really must implement 
Gio::ActionMap in your class (which I doubt), there is one or (probably) 
two errors.


First, interfaces must come before the widget class in the list of base 
classes.


class LinuxChessboardWidget : public Gio::ActionMap, public 
cwmm::ChessPositionWidget

This is opposite to what's done in gtkmm's classes that wrap gtk classes.

Second, your constructor must call a special Glib::ObjectBase constructor that 
registers your class with its own GType in glib's GType system. For instance

LinuxChessboardWidget(..) : Glib::ObjectBase("myWidgetClass") . // Or 
whatever you want to call it.

This is an unusual way of using Gio::ActionMap. I don't know if these are the 
only necessary changes. Much more common is to use one of the classes that 
already implement Gio::ActionMap: Gio::SimpleActionGroup, Gtk::Application (via 
Gio::Application) or Gtk::ApplicationWindow.

___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Please help (core dump)

2020-07-25 Thread Carlo Wood
Hi Aitor,

is this gtkmm3? For example, Gtk::VBox is deprecated,
I'm using Gtk::Grid.

Currently my application just core dumps :(.
The backtrace is:

Thread 1 "tstcpp" received signal SIGSEGV, Segmentation fault.
0x76bc29c6 in g_action_map_add_action () from /usr/lib/libgio-2.0.so.0
(gdb) bt
#0  0x76bc29c6 in g_action_map_add_action () at /usr/lib/libgio-2.0.so.0
#1  0x778cc541 in Gio::ActionMap::add_action(Glib::ustring const&) () 
at /usr/lib/libgiomm-2.4.so.1
#2  0x778cc65e in Gio::ActionMap::add_action(Glib::ustring const&, 
sigc::slot const&) ()
at /usr/lib/libgiomm-2.4.so.1
#3  0x55573871 in 
LinuxChessboardWidget::LinuxChessboardWidget(Gtk::Window*, 
Glib::RefPtr) (this=
0x563bd928, drawable=0x563bd8a0, promotion=..., 
__in_chrg=, __vtt_parm=)
at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessboardWidget.cxx:164
#4  0x5557b68b in LinuxChessWindow::LinuxChessWindow() 
(this=0x563bd8a0, __in_chrg=, __vtt_parm=)
at /home/carlo/projects/cwchessboard/cwchessboard/LinuxChessWindow.cxx:4
#5  0x5556e473 in LinuxChessApplication::create_window() 
(this=0x555f6230) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessApplication.cxx:160
#6  0x5556e3ed in LinuxChessApplication::on_activate() 
(this=0x555f6230) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessApplication.cxx:155
#7  0x778bbc2c in 
Gio::Application_Class::activate_callback(_GApplication*) () at 
/usr/lib/libgiomm-2.4.so.1
#8  0x7694480a in g_signal_emit_valist () at 
/usr/lib/libgobject-2.0.so.0
#9  0x76944980 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#10 0x76bbea89 in  () at /usr/lib/libgio-2.0.so.0
#11 0x778bba8a in Gio::Application::local_command_line_vfunc(char**&, 
int&) () at /usr/lib/libgiomm-2.4.so.1
#12 0x778bbe51 in 
Gio::Application_Class::local_command_line_vfunc_callback(_GApplication*, 
char***, int*) () at /usr/lib/libgiomm-2.4.so.1
#13 0x76bbec0a in g_application_run () at /usr/lib/libgio-2.0.so.0
#14 0x5557a928 in main(int, char**) (argc=1, argv=0x7fffd448) at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChess.cxx:14

Frame #3 (the first that is my code) is:

#3  0x55573871 in 
LinuxChessboardWidget::LinuxChessboardWidget(this=0x563bd928, 
drawable=0x563bd8a0, promotion=...,__in_chrg=, 
__vtt_parm=)
at 
/home/carlo/projects/cwchessboard/cwchessboard/LinuxChessboardWidget.cxx:164
164   add_action("ModeShowCandidates", sigc::mem_fun(*this, 
::on_menu_mode_showcandidates));


Why would this core dump??

LinuxChessboardWidget is defined as:

class LinuxChessboardWidget : public cwmm::ChessPositionWidget, public 
Gio::ActionMap
{
  ...

I have to derive from Gio::ActionMap because its constructor is protected.
The call to `add_action` above is to that class.

Can someone tell me what I'm doing wrong?

Carlo


___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list