定義物件類別 static void fm_folder_class_init(FmFolderClass *klass) // 初始化 class info ,填寫 virtual function table { GObjectClass *g_object_class; FmFolderClass* folder_class; g_object_class = G_OBJECT_CLASS(klass); // 手動 type casting g_object_class->dispose = fm_folder_dispose; // 手動填寫 virtual destructor fm_folder_parent_class = (GObjectClass*)g_type_class_peek(G_TYPE_OBJECT); folder_class = FM_FOLDER_CLASS(klass); folder_class->content_changed = fm_folder_content_changed; // 填寫 virtual function table signals[ FILES_ADDED ] = // 註冊新的 signal g_signal_new ( "files-added", G_TYPE_FROM_CLASS ( klass ), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET ( FmFolderClass, files_added ), NULL, NULL, g_cclosure_marshal_VOID__POINTER, // marshaller function, 告訴 Gobject 如何傳遞參數,常需從 Makefile 生成 G_TYPE_NONE, 1, G_TYPE_POINTER); } static void fm_folder_init(FmFolder *folder) // constructor { ... } static void fm_folder_dispose(GObject *object) // destructor { (* G_OBJECT_CLASS(fm_folder_parent_class)->dispose)(object); // 手動呼叫父類別 destructor }