从 C++ 程序读取 gsettings

Reading gsettings from C++ program

我需要以编程方式从我的 C++ 程序中的 gsettings 获取 com.ubuntu.user-interface scale-factor 的值。有什么优雅的方法可以做到这一点,而不是调用 gsettings 二进制文件并解析它的输出吗?

有一个 C++ 绑定到 glibmm 中的 gsettings。使用它,可以如下所示从模式中读取值。请注意,我没有可对其进行测试的 Ubuntu 系统,因此具体情况取决于对文档的简短查看,该文档告诉我 scale-factor 是一个整数值。考虑到这一点:

#include <giomm/settings.h>
#include <iostream>

int main() {
  Glib::RefPtr<Gio::Settings> s = Gio::Settings::create("com.ubuntu.user-interface");
  int i = s->get_int("scale-factor");

  std::cout << i << std::endl;
}

另见 here

我无法 post 对 Wintermute 回答发表评论,因为声誉较低,所以我 post 在这里。

像我这样的新手可能会遇到问题,包括 <giomm/settings.h>(未找到):解决方案是附加到 gcc 编译命令 `pkg-config --cflags --libs glibmm-2.4 giomm-2.4`(带反引号)

If your source file is program.cc, you can compile it with:

g++ program.cc -o program `pkg-config --cflags --libs glibmm-2.4 giomm-2.4`

来自here