**

2014-04-04 2 views
0

내가 GTK + 3 C.에서**

복합 위젯 설정 속성을 사용하여 복합 위젯을 작성하고 속성을 얻으려고이 alsa_device_item 사용되는 GTK + 복합 위젯 ** 타입 정의 구조체에 g_value_get_pointer 사용하는 _alsa_device_items에 대한 struct 유형입니다.

내 포함 파일입니다.

#ifndef AUDIO_DEVICE_DIALOG_WIDGET_H 
#define AUDIO_DEVICE_DIALOG_WIDGET_H 

#ifdef __cplusplus 
extern "C" { 
#endif 


#include <gtk-3.0/gtk/gtk.h> 

#define AUDIO_DEVICE_DIALOG_WIDGET_TYPE (audio_device_dialog_widget_get_type()) 
#define AUDIO_DEVICE_DIALOG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUDIO_DEVICE_DIALOG_WIDGET_TYPE, AudioDeviceDialogWidget)) 
GType   audio_device_dialog_widget_get_type (void); 

typedef struct _audio_device_dialog_widget AudioDeviceDialogWidget; 
typedef struct _audio_device_dialog_widget_class AudioDeviceDialogWidgetClass; 

struct _audio_device_item { 
char *device_name; 
char *device_desc; 
gboolean is_available; 
}; 

typedef struct _audio_device_item audio_device_item; 

AudioDeviceDialogWidget  *audio_device_dialog_widget_new   (audio_device_item **device_items);   


#ifdef __cplusplus 
} 
#endif 

#endif /* AUDIO_DEVICE_DIALOG_WIDGET_H */ 

include 파일에서 볼 수 있듯이 alsa_device_item의 struct와 typedef를 정의합니다.

은 C 파일이 있습니다 :

#include <gtk-3.0/gtk/gtk.h> 
#include <string.h> 
#include "audio_device_dialog_widget.h" 
#include "audio_dev_box_widget.h" 

typedef struct audio_device_dialog_widget_private AudioDeviceDialogWidgetPrivate; 


struct _audio_device_dialog_widget 
{ 
GtkDialog parent; 
AudioDeviceDialogWidgetPrivate *priv; 

}; 

struct _audio_device_dialog_widget_class 
{ 
GtkDialogClass parent_class; 
}; 

struct audio_device_dialog_widget_private 
{ 
GtkWidget *save_button, *cancel_button, *audio_dialog_box; 

}; 



G_DEFINE_TYPE_WITH_PRIVATE(AudioDeviceDialogWidget,audio_device_dialog_widget,GTK_TYPE_DIALOG); 

enum { 
PROP_0, 
PROP_DEVICE_NAMES 
}; 


static void audio_device_dialog_widget_init(AudioDeviceDialogWidget *widget) { 
widget->priv = G_TYPE_INSTANCE_GET_PRIVATE(widget, AUDIO_DEVICE_DIALOG_WIDGET_TYPE, AudioDeviceDialogWidgetPrivate); 
gtk_widget_init_template(GTK_WIDGET(widget));  
} 


AudioDeviceDialogWidget *audio_device_dialog_widget_new(audio_device_item **device_items) { 
return g_object_new(AUDIO_DEVICE_DIALOG_WIDGET_TYPE,"devices_list",device_items,NULL); 
} 

static void audio_device_dialog_widget_set_devices(AudioDeviceDialogWidget *widget,const audio_device_item **device_items) { 
g_return_if_fail(AUDIO_DEVICE_DIALOG_WIDGET(widget)); 
int i=0; 
while (device_items[i] != NULL) { 
    AudioDevBoxWidget *audio_dev_box_widget = audio_dev_box_widget_new(device_items[i]->device_name, device_items[i]->device_desc, device_items[i]->is_available); 
    gtk_box_pack_start(GTK_BOX(widget->priv->audio_dialog_box),GTK_WIDGET(audio_dev_box_widget),FALSE, FALSE, 0);   
    i++; 
} 
} 

const audio_device_item **audio_device_dialog_widget_get_devices(AudioDeviceDialogWidget *widget) { 
    g_return_val_if_fail (AUDIO_DEVICE_DIALOG_WIDGET (widget), NULL); 
    const audio_device_item **devices = NULL; 
    return devices; 
} 

static void 
audio_device_dialog_widget_set_property (GObject   *object, 
        guint   prop_id, 
        const GValue *value, 
        GParamSpec  *pspec) 
{ 
    AudioDeviceDialogWidget *widget = AUDIO_DEVICE_DIALOG_WIDGET (object); 

    switch (prop_id) 
    { 
case PROP_DEVICE_NAMES: 
    audio_device_dialog_widget_set_devices(widget, g_value_get_pointer(value)); 
     break; 
default: 
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 
    break; 
} 
} 

static void 
audio_device_dialog_widget_get_property (GObject   *object, 
        guint   prop_id, 
        GValue   *value, 
        GParamSpec  *pspec) 
{^ 
    AudioDeviceDialogWidget *widget = AUDIO_DEVICE_DIALOG_WIDGET (object); 

switch (prop_id) 
{ 
case PROP_DEVICE_NAMES: 
    g_value_set_pointer (value, audio_device_dialog_widget_get_devices(widget));  
    break; 
default: 
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 
    break; 
} 
} 


static void audio_device_dialog_widget_class_init(AudioDeviceDialogWidgetClass *class) { 
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class); 
GObjectClass *gobject_class = G_OBJECT_CLASS(class); 

gobject_class->set_property=audio_device_dialog_widget_set_property; 
gobject_class->get_property=audio_device_dialog_widget_get_property; 
GParamSpec *obj_properties = 
     g_param_spec_string("devices_list","Devices List","Devices List",NULL,G_PARAM_READWRITE); 


g_object_class_install_property(gobject_class, PROP_DEVICE_NAMES,obj_properties); 

    gtk_widget_class_set_template_from_resource (widget_class, 
              "/com/tuxin/tuxmusicstudio/audio_device_dialog.glade"); 

gtk_widget_class_bind_template_child_private(widget_class, AudioDeviceDialogWidget, save_button); 
gtk_widget_class_bind_template_child_private(widget_class, AudioDeviceDialogWidget, cancel_button); 
gtk_widget_class_bind_template_child_private(widget_class, AudioDeviceDialogWidget, audio_dialog_box); 

} 

내 응용 프로그램을 실행할 때 나는 다음과 같은 중요한 메시지를 얻을 : 당신이 g_value_get_pointer 내 타입 정의 구조체를 허용하지 않습니다 볼 수 있도록

(tuxmusicstudio:15946): GLib-GObject-CRITICAL **: g_value_get_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed 

을 바늘.

아이디어^

당신은 할 필요가

답변

0

있는지 몇 가지 :?

  1. 가 확인 GValue -pointer이 NULL
  2. getsetG_VALUE_HOLDS_POINTER(value)이에 있는지 확인 아닌지 확인 is TRUE
  3. 무엇을 확인하십시오 G_VALUE_TYPE_NAME (value) 실제로 보유하고 있습니다)
  4. 더 많은 디버그 플래그를 추가하십시오 - 제공 한 디버그 정보의 한계는 말할 것도 없습니다.