g_object_new:从g_应用程序的调用中断言发送通知()

g_object_new:从g_应用程序的调用中断言发送通知(),c,gtk,mingw,assert,msys2,C,Gtk,Mingw,Assert,Msys2,我使用与MSYS2一起安装的最新GTK+,每当我尝试使用 g\u应用程序\u发送\u通知()它总是导致以下结果 断言: 为什么我认为这是一个bug——因为我在我的代码旁边尝试了很多代码示例 (不管怎样,它们都很像地雷),都是让它发挥作用的人 (包括拉尔斯·尤伯尼克尔(Lars Uebernickel)的不作为)这一切都是一样的 哀叹 断言,然后是崩溃。现在我真的不知道这意味着什么,因为 可能在gtk内部,但我真的希望你们中的一些人可能有 这方面的线索或经验 安装(GNU coreutils)8

我使用与MSYS2一起安装的最新GTK+,每当我尝试使用
g\u应用程序\u发送\u通知()
它总是导致以下结果 断言:

为什么我认为这是一个bug——因为我在我的代码旁边尝试了很多代码示例 (不管怎样,它们都很像地雷),都是让它发挥作用的人 (包括拉尔斯·尤伯尼克尔(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.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;
}
#如果定义有配置#
#包括“config.h”
#恩迪夫
#包括
#定义图标路径“/PATH/trash\u 16x16.gif”
int main(int argc,char*argv[])
{
gaapplication*应用程序;
app=g_application_new(“org.one”,g_application_FLAGS_NONE);
如果(!应用程序)
{
g_打印(“错误应用程序\n”);
}
其他的
{
if(g_应用程序_寄存器(应用程序,空,空))
{
识别*通知;
GFile*文件;
GIcon*图标;
通知=g_通知_新(“一”);
g_通知_集_体(通知,“Hello world”);
file=g_file_new_用于_路径(图标_路径);
图标=g_文件\u图标\u新(文件);
g_通知_设置_图标(通知,g_图标(图标));
g_应用程序发送通知(应用程序,空,通知);
g_对象_unref(图标);
g_object_unref(文件);
g_object_unref(通知);
g_object_unref(应用程序);
g_print(“是”\n);
}
其他的
{
g_print(“否”);
}
}
返回0;
}


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

没有在W32上工作的通知后端,已确认。有一次,贡献者确实希望创建这样的API,但所需的API(W32 toast notifications)仅限于COM,而且MinGW-w64还没有必要的头。


具体来看glib源代码和GNotificationBackend接口,我们可以看到它很简单

现在,您可以在GTK中完成它……或者我们可以用正确的方法(TM)完成它,并为它实现一个D-Bus服务器。通知服务器的好处是,即使在应用程序终止后,通知也可以持久存在。此外,GTK已经有了与通知服务器对话的后端,因此您只需要在W32上启用这些后端(乍一看,代码没有使用任何在W32上不起作用的东西)。此外,通过这种方式,服务器将透明地使用
Shell\u NotifyIcon
(在Windows 7及更早版本上)或toast通知(在Windows 8及更高版本上;如果您有机会实现这些通知)


如果您想保持跨平台性,另一个选项是在DLL中创建
Shell\u NotifyIcon
实现,如果检测到windows,请使用
Shell\u NotifyIcon
如果没有,请按照您的意愿进行GNotification。

首先,既然不是GTK bug追踪器,为什么要在这里发布?如果你想让我们让你放心,你应该发布一个MCVE。@EugeneSh如果我误解了,很抱歉,但什么是MCVE?也不是针对编程相关的问题。这是与编程相关的问题。如果问题中包含对g_应用程序的调用,您的问题会更好。但我认为这可能没什么大不了的,所以:我没有投反对票,是的,这是针对编程相关的问题。但我在这里看不到任何问题。@JoséFonte谢谢:)如果我找到解决方案。我会把它寄出去。
#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;
}