The GVarianttarget cannot be passed to Gio::MenuItem#set_action_and_target_value.
Test code:
require "gtk4"
menu_item = Gio::MenuItem.new(nil, nil)
# Does not work
variant = GLib::Variant.new("test")
menu_item.set_action_and_target_value("app.some_action", variant)
# Also does not work
menu_item.set_action_and_target_value("app.some_action", "test")
# Not even this works
menu_item.set_action_and_target_value("app.some_action", nil)
Exception:
# Exception 1
Unhandled exception: Unable to wrap a Pointer(Void) into a GVariant. (ArgumentError)
from lib/gtk4/lib/gi-crystal/src/bindings/g_lib/variant.cr:20:15 in 'initialize'
from lib/gtk4/lib/gi-crystal/src/bindings/g_lib/variant.cr:5:5 in 'new'
from lib/gtk4/lib/gi-crystal/src/auto/gio-2.0/menu_item.cr:272:7 in 'set_action_and_target_value'
from src/test2.cr:19:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:115:5 in 'main_user_code'
from /usr/share/crystal/src/crystal/main.cr:101:7 in 'main'
from /usr/share/crystal/src/crystal/main.cr:127:3 in 'main'
from /lib64/libc.so.6 in '??'
from /lib64/libc.so.6 in '__libc_start_main'
from /var/home/blobcodes/.cache/crystal/crystal-run-test2.tmp in '_start'
from ???
# Exception 2
Unhandled exception: Unable to wrap a Pointer(UInt8) into a GVariant. (ArgumentError)
from lib/gtk4/lib/gi-crystal/src/bindings/g_lib/variant.cr:5:5 in 'initialize'
from lib/gtk4/lib/gi-crystal/src/bindings/g_lib/variant.cr:5:5 in 'new'
from lib/gtk4/lib/gi-crystal/src/auto/gio-2.0/menu_item.cr:272:7 in 'set_action_and_target_value'
from src/test2.cr:17:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:115:5 in 'main_user_code'
from /usr/share/crystal/src/crystal/main.cr:101:7 in 'main'
from /usr/share/crystal/src/crystal/main.cr:127:3 in 'main'
from /lib64/libc.so.6 in '??'
from /lib64/libc.so.6 in '__libc_start_main'
from /var/home/blobcodes/.cache/crystal/crystal-run-test2.tmp in '_start'
from ???
The
GVariant
target
cannot be passed toGio::MenuItem#set_action_and_target_value
.Test code:
Exception:
Gio::MenuItem#set_action_and_target_value
implementation:I think the conversion to a
GLib::Variant
has to be done before using to_unsafe.