在`GLib.ListStore'的上下文中不存在`find'这个名字。

问题描述 投票:0回答:1

我完全不明白为什么会抛出这个错误。该 缬草酮 显示这个函数存在。append函数也能用。下面是重现它的代码。

class some_object : GLib.Object {
    public int val {get; construct;}
    public some_object (int val) {
        Object (
            val: val
        );
    }
}

class ExampleList : Gtk.ApplicationWindow {
    construct {
        var dummy = new some_object(0);
        var model = new GLib.ListStore (GLib.Type.from_instance (dummy));
        model.append (dummy);
        uint position;


        model.find (dummy, out position);

        //    ^^^^

    }
}

class MyApplication : Gtk.Application {
    public MyApplication () {
        Object (
            application_id: "com.example.listbox"
        );
    }
    public override void activate () {
        new ExampleList (). show_all ();
    }
}

public static int main (string[] args) {
    return new MyApplication (). run (args);
}

编译时我用了:

valac --pkg=gtk+-3.0 so.vala

而我得到的错误是:

so.vala:18.9-18.18: error: The name `find' does not exist in the context of `GLib.ListStore'
        model.find (dummy, out position);
        ^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

listbox find gtk glib vala
1个回答
1
投票

从你链接到的参考文档中。

[ Version ( since = "2.64" ) ]

这个GIO版本是今年才发布的: 很可能你使用的是一个不包含这个函数的旧版本。

© www.soinside.com 2019 - 2024. All rights reserved.