【问题标题】:Reading gsettings from C++ program从 C++ 程序中读取 gsettings
【发布时间】:2017-05-01 00:16:18
【问题描述】:

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

【问题讨论】:

    标签: c++ linux gsettings


    【解决方案1】:

    glibmm 中有一个与 gsettings 的 C++ 绑定。有了它,可以从模式中读取一个值,如下所示。请注意,我没有用于测试的 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

    【讨论】:

      【解决方案2】:

      由于声誉低,我无法对 Wintermute 答案发表评论,因此我将其发布在这里。

      Newbe 和我一样,可能会遇到问题,包括 &lt;giomm/settings.h&gt;(未找到):解决方案是附加到 gcc 编译命令 `pkg-config --cflags --libs glibmm-2.4 giomm-2.4`(带反引号)

      如果你的源文件是program.cc,你可以编译它:

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

      来自here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多