Getting a dbus interface property using gdbus

I’m trying to get properties that’s been set on an interface and nothing I’ve tried seems to work.

This is how I’m trying to access the property;

 result = g_dbus_connection_call_sync (connection,
                                       name,
                                       "/org/gtk/GDBus/TestObject",
                                       "org.gtk.GDBus.TestInterface",
                                       "Get",
                                       g_variant_new ("(s)",
                                                      "WritingAlwaysThrowsError"),
                                       G_VARIANT_TYPE("(s)"),
                                       G_DBUS_CALL_FLAGS_NONE,
                                       -1,
                                       NULL,
                                       &error);

I get this error;

**
ERROR:gdbus-example-property.c:56:on_name_appeared: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method ?Get? (g-dbus-error-quark, 19)
Bail out! ERROR:gdbus-example-property.c:56:on_name_appeared: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method ?Get? (g-dbus-error-quark, 19)
Aborted (core dumped)

The server has the get_property callback set for the interface but that doesn’t seem to get called, I wrote an implementation for the “Get” method, and that also throws the same error.

Use the org.freedesktop.DBus.Properties interface, not the org.gtk.GDBus.TestInterface.

When I use that interface, I get this error;

ERROR:gdbus-example-property.c:38:on_name_appeared:
assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod:
No such interface ?org.freedesktop.DBus.Properties? on object at
path /org/gtk/GDBus/TestObject (g-dbus-error-quark, 19)
Bail out! ERROR:gdbus-example-property.c:38:on_name_appeared:
assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod:
No such interface ?org.freedesktop.DBus.Properties? on object at path
/org/gtk/GDBus/TestObject (g-dbus-error-quark, 19)

Which seems a bit strange because the server can also emit on that interface from the same bus name.

Use D-Spy to look at the server and check that it’s exporting the right interfaces.

1 Like

This was very helpful, the server was exporting the right interfaces but I was passing the wrong arguments to the method, thank you!

This is the new method call;

  result = g_dbus_connection_call_sync (connection,
                                        name,
                                        "/org/gtk/GDBus/TestObject",
                                        "org.freedesktop.DBus.Properties",
                                        "Get",
                                        g_variant_new ("(ss)",
                                                       "org.gtk.GDBus.TestInterface",
                                                       "WritingAlwaysThrowsError"),
                                        G_VARIANT_TYPE("(v)"),
                                        G_DBUS_CALL_FLAGS_NONE,
                                        -1,
                                        NULL,
                                        &error);
1 Like

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