How to properly use Gdk.Display method get_monitors() in vala

i have this piece of vala code that want work, when i compile it return this error:
"error: Assignment: Cannot convert from GLib.Object? to Gdk.Monitor?",
how can i resolve this problem?

Gdk.Display display = Gdk.Display.get_default ();
GLib.ListModel monitors = display.get_monitors ();
 uint n_monitors = monitors.get_n_items ();
stdout.printf(monitors.get_item_type ().name ()); //Return GdkMonitor
 for (uint i = 0; i < n_monitors; i++) {
            Gdk.Monitor monitor = monitors.get_item (i);
            Gdk.Rectangle geometry = monitor.get_geometry ();
            // ...........

Seems that you should convert object to Gdk.Monitor explicitly

Gdk.Monitor monitor = (Gdk.Monitor)monitors.get_item (i);
1 Like

Thank you very much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.