Clutter使用的問題總結

1. 對結構體的賦值:
   ClutterColor      stage_color;
   stage_color = {0xff, 0xff, 0x0, 0xff};
   報告錯誤爲:  error: expected expression before '{' token
   總結: 結構體要麼在初始化時賦值,要麼需要對其各項分別賦值。
   如上列中:stage_color.red = 0xff, stage_color.green = 0xff, stage_color.blue = 0x0, stage_color.alpha = 0xff;
   
2. 誤以爲gpointer 只是基本類型(如int),聲明函數void on_foreach_show(gint data, gpointer *user_data) {...};
   總結: gpointer 爲 (void *).
   
3. 對(void *) 類型的指針解引用時,要先強制轉化爲指針的原本類型,否則無法解引用.
   報錯爲:
   main.c:82: warning: dereferencing 'void *' pointer
   main.c:82: error: void value not ignored as it ought to be
   
4. g_signal_connect 帶進的參數無效;
   比如:g_signal_connect (row_actor, "key-focus-out", G_CALLBACK (row_actor_focus_out_event), pItem);
   回調函數的聲明爲:
   static gboolean row_actor_event_dispose (ClutterActor      *row_text_actor,
                   ClutterEvent    *event,
                   SubItem         *pItem)
   {...}
    總結:在g_signal_new時,指定的函數指針除了instance外只帶了一個參數(clutter-actor.h文件),如下:
            void  (* key_focus_out)(ClutterActor         *actor);    
          所以回調函數應該聲明爲如下即可:
              static gboolean row_actor_event_dispose (ClutterActor      *row_text_actor,
                                                        SubItem         *pItem)
           
5. xargs:  build and execute command lines from standard input
  ls   |   xargs   grep   xxx    <=>   grep   xxx   `ls`  <=> 在ls的列表中找xxx字符串  
  ls   |   grep   xxx            <=>  在ls的列表中找xxx文件  

6. 如何在命令行中使用有空格的文件名和路徑?
      方法1:g_sprintf(play_info, "find /"%s/" -print0 -exec /bin/media_player -src {} //;", pItem->focus_in_row_file_name);
             system(play_info); /* 小技巧 */
      方法2:g_sprintf(play_info, "/bin/media_player -src /"%s/"", pItem->focus_in_row_file_name);
             system(play_info);  /* 使用""包括路徑的整體 */

 

7. EXIT_FAILURE 和 EXIT_SUCCESS 在 stdlib.h 中定義.

8. 頭文件循環包含問題的解決:
   a. 使用ifndef/define/endif等結構進行預處理, 如下:
       #ifndef __CLUTTER_ACTOR_H__
       #define __CLUTTER_ACTOR_H__
       #include <clutter-actor.h>
       #endif
   b. 設置一個統一的頭文件;
   c. 將可能導致循環包含的頭文件寫到*.c文件中.

發佈了45 篇原創文章 · 獲贊 1 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章