Re: Gtk3::Stock->add: need an array ref to convert to GArray

On 29.02.2012 17:51, Hubert Mauchle wrote:
Gtk3::Stock->add ($items);

This gives the error
"need an array ref to convert to GArray" when calling the function

Yeah, our error messages aren't very good. Patches welcome. There are a couple of issues in this case:

• As gtk_stock_add is a function, not a method, it's mapped as Gtk3::Stock::add($items). The '->' syntax implicitly passes the package name, which is not an array ref.

• If you change it to Gtk3::Stock::add([["demo", "demo", 0, 0, undef]]) you'll be greeted by

  need a hash ref to convert to struct of type StockItem

We haven't implemented the conversion from an array ref to a struct yet. (Again, patches welcome.)

• But even if you change it to

  Gtk3::Stock::add ([{stock_id => "demo", label => "demo",
                      modifier => 0, keyval => 0,
                      translation_domain => undef}])

you'll get

  Could not set field 'stock_id'

That's because raw string fields in structs cannot be set reliably without further information: mostly, you don't know what allocator to use. We could work around this in this case because we will be the ones freeing this stuff anyway. But we don't have that kind of special-case logic yet, and I'm not sure whether it would be advisable to add it.

In short: there's currently no way to use gtk_stock_add from Gtk3. I think all the other introspection and bindings author would agree that gtk+ should add API to either construct a GtkStockItem, or API that directly takes the five arguments that are in a GtkStockItem.

There are also other ways to add custom stock items; one is explained at <>.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]