简体   繁体   English

无法在 Gjs 中创建 GArray

[英]Unable to create a GArray in Gjs

I try to create a GArray but I have always the same error :我尝试创建一个 GArray 但我总是有同样的错误:

const GLib = imports.gi.GLib; const GLib = import.gi.GLib;

var garray = new GLib.Array(true, true, 1); var garray = new GLib.Array(true, true, 1); // Unable to construct boxed type Array since it has no zero-args , can only wrap an existing one // 无法构造盒装类型数组,因为它没有零参数,只能包装现有的

var garray = new GLib.Array(); var garray = new GLib.Array(); // Unable to construct boxed type Array since it has no zero-args , can only wrap an existing one // 无法构造盒装类型数组,因为它没有零参数,只能包装现有的

I need a GArray to use it in the GnomeKeyring.item_create_sync method :我需要一个 GArray 在 GnomeKeyring.item_create_sync 方法中使用它:

GnomeKeyring.item_create_sync( "login", 4, "name", new GLib.Array(true, true, 1) "pass", true); GnomeKeyring.item_create_sync("登录", 4, "名称", new GLib.Array(true, true, 1) "pass", true);

I tried other type of array instead of GArray, here are the errors我尝试了其他类型的数组而不是 GArray,这是错误

  • [] -> Object 0xb5d120d0 is not a subclass of (null), it's a Array [] -> 对象 0xb5d120d0 不是 (null) 的子类,它是一个数组
  • new Array() -> Object 0xb5e12138 is not a subclass of (null), it's a Array new Array() -> Object 0xb5e12138 不是 (null) 的子类,它是一个数组
  • {} -> Object 0xb5d0b1b0 is not a subclass of (null), it's a Object {} -> 对象 0xb5d0b1b0 不是 (null) 的子类,它是一个对象
  • 5 -> Unhandled GType GArray unpacking GArgument from Number 5 -> 未处理的 GType GArray 从 Number 解包 GArgument
  • "5" -> Expected type interface for Argument 'attributes' but got type 'string' "5" -> 参数“属性”的预期类型接口,但类型为“字符串”

If anyone has a solution for GArray or for GnomeKeyring.item_create_sync如果有人有GArrayGnomeKeyring.item_create_sync的解决方案

Read /usr/share/gir-1.0/GnomeKeyring-1.0.gir and search for function name="item_create_sync" .阅读/usr/share/gir-1.0/GnomeKeyring-1.0.gir并搜索function name="item_create_sync" You have all required parameters there and it seems to me that you need a plain list.你有所有必需的参数,在我看来你需要一个简单的列表。 GnomeObjectIntrospection will translate it to the GArray when needed. GnomeObjectIntrospection 会在需要时将其转换为 GArray。

The GNOME Shell's retrospection will convert between JS and GNOME types on its own accord where possible and required. GNOME Shell 的回顾将在可能和需要的情况下自行在 JS 和 GNOME 类型之间进行转换。 If you create an array in the JS space and pass it to a function that requires a GArray, the Shell will convert if you pass the array as argument.如果您在 JS 空间中创建一个数组并将其传递给需要 GArray 的函数,则如果您将数组作为参数传递,Shell 将进行转换。

The only objects that aren't converted are those whose classes exist in one space, but not the other.唯一没有被转换的对象是那些类存在于一个空间而不是另一个空间的对象。 Like the GNOME File Objects, as JS has no native filehandlers.就像 GNOME 文件对象一样,JS 没有本地文件处理程序。 You can use the .toString() method on filestreams to get their contents as a string, or call the reading methods to get the binary values as an array of integers.您可以在文件流上使用.toString()方法以字符串形式获取其内容,或调用读取方法以整数数组形式获取二进制值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM