My Gio.SimpleAction instance declaration looks like so:
const copyColorAction = new Gio.SimpleAction({
name: "copy-color",
parameterType: GLib.VariantType.new("s"),
});
I get the error below when I run the code above.
actionhelper: action win.copy-color can't be activated due to parameter type mismatch (parameter type s, target type NULL)
unable to set property 'action-target' of type 'GVariant' from value of type 'gchararray'
It only works when I replace the lookup with the code below.
I suspect I am not using the correct type string , type string combination, or there is something I should be doing in the lookup to convert the string value to a string enclosed in quotes. What could be the problem?
This is actually just a (possibly unavoidable) quirk of GActions with parameters. If you set the action-target first (i.e. “above” the action-name, you should avoid the critical warning.
Unfortunately, moving the action-target property above its action-name sibling still gives the same warning and error. It doesn’t register the action at all because the button remains inactive. This could be a lookup bug or something related to lookup. Hard-coding the string in quotes seems fine but looking it up dynamically is where things start to fail.
Gtk-WARNING **: 08:48:40.452: actionhelper: action win.copy-color can't be activated due to parameter type mismatch (parameter type s, target type NULL)
GLib-GObject-CRITICAL **: 08:48:40.452: unable to set property 'action-target' of type 'GVariant' from value of type 'gchararray'
However, when I create an additional property of the GVariant type to wrap the string I need in the lookup Gobject, it registers the action and the critical error seems to disappear but the warning still remains.
color_variant_type: GObject.param_spec_variant(
"color_variant_type",
"colorVariantType",
"Picked color in gVariantType datatype",
GLib.VariantType.new("s"),
null,
GObject.ParamFlags.READWRITE
),
I still get tons of this warning:
Gtk-WARNING **: 09:02:23.990: actionhelper: action win.copy-color can't be activated due to parameter type mismatch (parameter type s, target type NULL)
Ah, I see. I guess that the expression is resolving after the action-name is set. If the parameter type is a string, you should probably be able to set the action-name to a detailed action, such as win.copy-color::color or win.copy-color('hello world').
Using detailed action name removes the error but the action is not being registered. The button remains inactive. Even hard-coding the value like this doesn’t register the action.
If that might work, and get rid of the warning/critical? I’m making an assumption here, but I guess these buttons aren’t intended to ever be insensitive or not have a target?
I feel like I might not be giving you the best advice here, but I’m missing the larger picture of the application, so hopefully I’m not taking you down the wrong road
I’ve seen the same in C, so I believe it’s just a quirk of how actions with parameters work. I guess it’s just necessary to assume the programmer has made a mistake if the action is set before the target is known, otherwise you’d have to warn them at activation-time, and that might be inefficient or crashy.