GSettings值似乎在我的C代码中有所改变,但它不会持续存在。 dconf-editor显示它保持不变(默认的“picture-uri”设置)。
我错过了什么吗?
#include <stdio.h>
#include <gio/gio.h>
int main() {
GSettings * background_settings = g_settings_new("org.gnome.desktop.background");
printf("\"picture-uri\" setting is writable? \n%d\n\n", g_settings_is_writable(background_settings, "picture_uri"));
GVariant * picture_uri_setting = g_settings_get_value(background_settings, "picture-uri");
char * picture_uri_setting_value;
g_variant_get(picture_uri_setting, "&s", &picture_uri_setting_value);
printf("Before: %s\n", picture_uri_setting_value);
GVariant * new_picture_uri_setting = g_variant_new("&s", "file:///tmp/wall.jpg");
g_settings_set_value(background_settings, "picture-uri", new_picture_uri_setting);
picture_uri_setting = g_settings_get_value(background_settings, "picture-uri");
g_variant_get(picture_uri_setting, "&s", &picture_uri_setting_value);
printf("After: %s\n", picture_uri_setting_value);
return 0;
}
这是我编译它的方式:
gcc -Wall -g --save-temps main.c $(pkg-config --libs --cflags gtk+-3.0)
感谢。