首页 > 解决方案 > 如何在 vala 中创建通知类

问题描述

我正在学习 vala 语言,我想创建一个服务来触发通知。那是我的代码

public class Services.Notifications : Glib.Object {
  

  public void sendNotification (string title, string body,string icon_name, GLib.NotificationPriority priority) {
      var notification = new Notification (title);
      notification.set_body (body);
      notification.set_icon (new ThemedIcon (icon_name));
      notification.set_priority (priority);

      send_notification ("com.github.andirsun.myapp", notification);
  }
}

但我面临这个错误

class Notifications: null
base type `null' of class `Services.Notifications' is not an object type

我在 meson.build 文件中添加了文件 Services/Notification.vala 无效

标签: gtkglibvala

解决方案


您的基类名称中有错字 -Glib.Object应该是GLib.Object(注意大写L


推荐阅读