【问题标题】:Initialization of GtkApplication - Should I use GObject's "init" or GtkApplication's "startup"?GtkApplication 的初始化——我应该使用 GObject 的“init”还是 GtkApplication 的“startup”?
【发布时间】:2019-05-10 10:58:09
【问题描述】:

我正在尝试创建一个 GTK-3 应用程序,并且在初始化过程中我想检查 GSetting 的值是否已设置,否则我想显示一个“启动”对话框,该对话框仅在第一次运行时可见。

GObject 有一个_init 后缀,可用于类初始化。在这种情况下,MyGtkApplication 将被构造,它基于GtkApplicationGtkApplicationstartup-thing 也可用于初始化。

在那个例子中,我仍然需要为 GApplicationClass 实现 _init 函数。

GApplicationClass *gapp_class;

gapp_class = G_APPLICATION_CLASS (class);
gapp_class->startup = app_startup;

// This must be always implemented, because the MyGtkApplication is "GtkApplication"-based class.
void app_init(MyGtkApplication *app) {
  // Check and show the modal dialog if key does not exist?
}

// This will overwrite the GApplicatio's "startup".
void app_startup(GApplication *app) {
  // Check and show the modal dialog if key does not exist?
}

目前app_init 没有正文。

有什么区别,我应该使用哪一个?

问候, TheAifam5.

【问题讨论】:

    标签: c gtk3 glib


    【解决方案1】:

    init 基本上是GApplication 对象的构造函数。使用它来初始化对象的私有数据并将其置于一致状态。

    startup 在应用程序启动时被调用。特别是,在您调用g_application_run() 并启动主事件循环之后,应用程序已检查它是唯一运行的实例。在此之前您不想显示对话框,所以startup 是这样做的正确位置。

    【讨论】:

    • 感谢您的回答。祝你今天过得愉快! :)
    猜你喜欢
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多