【问题标题】:g_object_new: assert from a call of g_application_send_notification()g_object_new:通过调用 g_application_send_notification() 断言
【发布时间】:2017-09-26 21:30:30
【问题描述】:

我使用与 MSYS2 一起安装的最新 GTK+,每当我尝试使用 g_application_send_notification() 它总是导致以下结果 断言:

(Notification Project.exe:27780): GLib-GObject-CRITICAL **: g_object_new:
assertion 'G_TYPE_IS_OBJECT (object_type)' failed

为什么我认为这是一个错误 - 因为我在我的旁边尝试了许多代码示例 (无论如何,它们都非常像地雷),让它工作的人 (包括 Lars Uebernickel 的通知),这一切都一样 哀叹。 断言,然后是崩溃。现在我真的不知道这意味着什么,因为它 可能在 gtk 内部,但我真的希望你们中的一些人可能有 这方面的线索或经验。

  • 安装 (GNU coreutils) 8.25
  • GIO 版本 2.52.3
  • mingw32/mingw-w64-i686-gtk-engine-unico 1.0.2-2 [已安装]
  • mingw32/mingw-w64-i686-gtk3 3.22.16-1 [已安装]
  • mingw32/mingw-w64-i686-gtkmm3 3.22.0-1 [已安装]
  • mingw32/mingw-w64-i686-spice-gtk 0.33-1 [已安装]
  • mingw32/mingw-w64-i686-webkitgtk3 2.4.11-4 [已安装]
  • mingw64/mingw-w64-x86_64-gtk-engine-unico 1.0.2-2 [已安装]
  • mingw64/mingw-w64-x86_64-gtk3 3.22.16-1 [已安装]
  • mingw64/mingw-w64-x86_64-gtkmm3 3.22.0-1 [已安装]
  • mingw64/mingw-w64-x86_64-spice-gtk 0.33-1 [已安装]
  • mingw64/mingw-w64-x86_64-webkitgtk3 2.4.11-4 [已安装]

生成此断言的代码示例:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gtk/gtk.h>

#define ICON_PATH "/path/trash_16x16.gif"

int main (int argc, char *argv[])
{
    GApplication *app;

    app = g_application_new ("org.one", G_APPLICATION_FLAGS_NONE);
    if(!app)
    {
        g_print ("Error app\n");
    }
    else
    {
        if(g_application_register (app, NULL, NULL))
        {
            GNotification *notification;
            GFile *file;
            GIcon *icon;
            notification = g_notification_new ("one");
            g_notification_set_body (notification, "Hello world");
            file = g_file_new_for_path (ICON_PATH);
            icon = g_file_icon_new (file);
            g_notification_set_icon (notification, G_ICON (icon));
            g_application_send_notification (app, NULL, notification);
            g_object_unref (icon);
            g_object_unref (file);
            g_object_unref (notification);
            g_object_unref (app);
            g_print ("yes\n");
        }
        else
        {
            g_print ("no\n");
        }
    }
    return 0;
}

我能做些什么来绕过这个问题,甚至可以解决它吗?

【问题讨论】:

  • 首先,SO 不是 GTK 错误跟踪器,所以为什么要在这里发帖?如果您希望我们让您放心,您应该发布 MCVE。
  • @EugeneSh 对不起,如果我误解了,什么是 MCVE?也不是针对与编程相关的问题。这是编程相关的问题。
  • 如果问题中包含您对 g_application_send_notification 的调用,您的问题会更好。但我认为这可能无关紧要,所以:我没有反对
  • stackoverflow.com/help/mcve 是的,它是针对与编程相关的问题。但我在这里没有看到任何问题。
  • @JoséFonte 谢谢 :) 如果我找到解决方案。我会发布它。

标签: c gtk mingw assert msys2


【解决方案1】:

确认没有适用于 W32 的通知后端。贡献者曾经希望创建这样的 API,但所需的 API(W32 toast 通知)仅适用于 COM,而 MinGW-w64 还没有必要的标头。


具体看glibgio源码和GNotificationBackend接口,可以看出很简单。

现在,您可以在 GTK 中执行此操作...或者我们可以以正确的方式 (TM) 执行此操作并为其实现 D-Bus 服务器。通知服务器的好处是即使在应用程序终止后通知也可以持续存在。此外,GTK 已经有与通知服务器通信的后端,因此您只需要在 W32 上启用这些后端(乍一看,代码没有使用任何在 W32 上不起作用的东西)。此外,服务器将透明地使用Shell_NotifyIcon(在 Windows 7 及更早版本上)或 toast 通知(在 Windows 8 及更高版本上;如果您有机会实现这些)。

如果您想保持跨平台性,另一种选择是在 DLL 中创建 Shell_NotifyIcon 实现,如果检测到 Windows,则使用 Shell_NotifyIcon,如果没有,则使用 GNotification。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2023-02-09
    相关资源
    最近更新 更多