I may be very much mistaken, but if I read the documentation for
Gtk::Entry::set_icon_from_icon_name (located at https://developer.gnome .org/gtkmm/stable/classGtk_1_1Entry.html#a7c61eafbce9c3293566c1b6cc86f8
9e1) it seems that to remove an icon from an Entry, one should provide
an std::nullptr_t as the first parameter.
Doing this results in a segmentation fault, which makes sense because
one cannot construct a Glib::ustring with a nullptr. I have also tried
providing the string "nullptr", since the documentation is not
completely clear and this results in the "broken image" being shown.
This feels like - at the least - a documentation bug. I could not find
the correct way to do this. How can I remove an image from an Entry?
I had not thought of trying an empty string, though it's good to know that this is the usual answer to nullptr's that have become objects. I have tried it and it does indeed work as expected when I pass an empty string.
On a side note, I had already got it working the way I wanted by using Gtk::Entry::set_icon_from_pixbuf and passing an empty Glib::RefPtr to it. I noticed that it does have a default constructor that creates an empty object, so the following works:
However, it does not have a constructor taking an std::nullptr_t, which would be a more obvious way to do it, one could then call:
This models the way that std::shared_ptr works, and IMHO it's more declarative. It should be a simple one-liner to fix this, I'll see about creating a patch for this later.
On di, 2017-07-25 at 14:58 +0100, Daniel Boles wrote:
The documentation is auto generated from the C documentation, which does not always work very well, especially for conversions from char* to Glib::ustring as you saw.
Did you try just passing an empty string? That's usually how you need to mentally translate "nullptr".
I wonder if the documentation converter can possibly do this conversion for us...
On 26 July 2017 at 08:20, Martijn Otto via gtkmm-list <[hidden email]> wrote:
I must admit I had missed that function, after reading the
documentation describing the usage of a "nullptr" to clear the image I
assumed that was the GTK way of doing things.
Well, yeah, it's a way, in that usually you can use a set() method with its argument being suitably-typed equivalent of 'empty' or 'null' to achieve unsetting. However, in many or perhaps most cases, there is an unset() to make things simpler, and IMO that is better API and should be offered/used where possible.
If you find any cases where there isn't an unset and the set(empty) is unintuitive or clumsy, then it's probably worth submitting an enhancement to Bugzilla - probably on the GTK+ side, since typically gtkmm just prefers to wrap what GTK+ offers.
That said, as you will have noticed, it's not uncommon for gtkmm to add extra convenience methods that GTK+ probably never will - especially when that "never will" is because the gtkmm methods depend on C++ convenience features. So it's possibly you'll find something that would be better done on the gtkmm side.
On Wed, 2017-07-26 at 09:52 +0100, Daniel Boles wrote:
> Well, yeah, it's a way, in that usually you can use a set() method
> with its argument being suitably-typed equivalent of 'empty' or
> 'null' to achieve unsetting.
I don't think we can generally assume that that works as expected.
> However, in many or perhaps most cases, there is an unset() to make
> things simpler, and IMO that is better API and should be offered/used
> where possible.
Yes, the unset_*() methods are more obvious. We just need to mention
them in the documentation.