2011-04-29 113 views
0
if(xmlStrEquals(cur->name, (const xmlChar *) "check")) // Find out which type it is 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, xmlGetProp(cur,"name"))),(gboolean) xmlGetProp(cur,"value")); 

else if(xmlStrEquals(cur->name, (const xmlChar *) "spin")) 
    gtk_adjustment_set_value(GTK_ADJUSTMENT (gtk_builder_get_object (builder, xmlGetProp(cur,"name"))),(gdouble) xmlGetProp(cur,"value")); 

else if(xmlStrEquals(cur->name, (const xmlChar *) "combo")) 
    gtk_combo_box_set_active(GTK_COMBO_BOX (gtk_builder_get_object (builder, xmlGetProp(cur,"name"))),(gint) xmlGetProp(cur,"value")); 

以下3個錯誤對應於上述3個if語句。編譯器類型警告和錯誤

main.c:125: warning: cast from pointer to integer of different size 
main.c:130: error: pointer value used where a floating point value was expected 
main.c:139: warning: cast from pointer to integer of different size 

如果你允許我提取違規部分:

(gboolean) xmlGetProp(cur,"value") 
(gdouble) xmlGetProp(cur,"value") 
(gint) xmlGetProp(cur,"value") 

爲什麼這些類型轉換導致這些錯誤?我該如何解決它們?

嘗試使用(gboolean *)等從GTK的線沿線收到警告:

warning: passing argument 2 of ‘gtk_toggle_button_set_active’ makes integer from pointer without a cast 
/usr/include/gtk-2.0/gtk/gtktogglebutton.h:82: note: expected ‘gboolean’ but argument is of type ‘gboolean *’ 
error: incompatible type for argument 2 of ‘gtk_adjustment_set_value’ 
/usr/include/gtk-2.0/gtk/gtkadjustment.h:93: note: expected ‘gdouble’ but argument is of type ‘gdouble *’ 
warning: passing argument 2 of ‘gtk_combo_box_set_active’ makes integer from pointer without a cast 
/usr/include/gtk-2.0/gtk/gtkcombobox.h:99: note: expected ‘gint’ but argument is of type ‘gint *’ 

回答

0

我固定它,像這樣:

(gboolean) *xmlGetProp(cur,"value") 
(gdouble) *xmlGetProp(cur,"value") 
(gint) *xmlGetProp(cur,"value") 

仍然不知道爲什麼工作,但我能猜到。

1

的​​返回一個字符串(如xmlChar *):

搜索並獲得相關的屬性值到一個節點這是實體替代。該函數在DTF屬性聲明中查找#FIXED或默認聲明值,除非DTD使用已被關閉。
[...]
返回:屬性值或NULL,如果沒有找到。這取決於調用者使用xmlFree()釋放內存。

調用者負責將該字符串解析爲任何形式(浮點,整數,布爾,...)。另請注意,主叫方也負責釋放返回的xmlChar *字符串。

解決您的問題,您需要將字符串轉換爲你通常的方式所需要的。並且不要忘記xmlFree返回的字符串。

+0

抱歉,我以爲'(類型)variable'是用通常的方法? – 2011-04-29 20:40:41