`
cloverprince
  • 浏览: 129477 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

GObject 00: A bottom-up introduction to the GObject system

阅读更多
This document introduces the GObject library.  This cannot replace the official tutorial/reference.  It is recommended to lookup the official reference every time you encountered new concepts.

--

After trying to learn GObject object system for more than ten times (and failed as many times as I have tried), I decided to try another approach.

Q: You are stupid.
A: Yeah.  I think I am.  Or I am just stuck.

Q: What made you stuck?
A: I have always believed that GLib/GObject is overly complicated and verbose and ugly in grammar and not suitable for everyday programming.  See how many boilerplates you need to define a class.  You need to include the name of the class in every method call.  You need to cast a lot to supress warnings. ... All of these haunted me and told me "you could not understand it" from time to time.

Q: Then?
A: I must believe GObject is simple.  (I really wonder if hypnotism work this well?)


-- Background information --

Q: What is GObject?
A: It is a part of the GLib library.  It allows you to write object-oriented programs in the C language.

Q: What is GLib?
A: A utility library in the C language.  It provides platform-transparency and helps in all trivial aspects like string manipulation, memory allocation, File/Network IO, concurrency/synchronization, event/signal/mainloop, dynamically loaded modules and a object-oriented type system, of course.  I guess it is a helper library to make GTK+ easier to implement, but it is not bound to GUI programming.

:: For more information, visit http://www.gtk.org/.


-- Blogging plan --

I will post more articles in my blog to record my process of learning.  By the way, this document may contain error (feedback is always welcome).  If you are in doubt, you should always consult the official GObject documentation which is the sub-ultimate authority of it.

Q: What is the ultimate authority, then?
A: The f**king source code, of course.  It is always right because it is what the library is compiled from.  Read it when the documentation fails to tell the whole story.

I shall create my own fundamental type, which I am not supposed to create since I am not Tim Janik.  Then I shall see whether my code works.  And then I will make it classed, instantiatable, inheritable.  Then add properties, signals and implement interfaces.  I will also consider GValue container later.

Q: Wait.  Who is asking question in these Q/A paragraphs?
A: Myself.  Many questions will be raised during learning.  I will try to answer my own questions.  (Be critical when reading my "answers")


-- A minimal GObject program --

Install GLib 2.x first.  Download at http://www.gtk.org/.  If you use the GLib provided by your distribution, make sure the development package is installed.  (glib2-devel for Fedora)

#include <glib-object.h>

int main() {
    g_type_init(); // This is necessary

    return 0;
}


Compile with:
引用
gcc `pkg-config --cflags --libs gobject-2.0` example.c -o example



分享到:
评论
4 楼 cloverprince 2010-04-18  
garfileo 写道
> you could not underand it

s/underand/understand/g ?


yeah.   it is a typo
3 楼 garfileo 2010-04-16  
> you could not underand it

s/underand/understand/g ?
2 楼 cloverprince 2010-01-07  
garfileo 写道
话说这个有没有中文版,没有的话我翻了阿

没有。我的本意就是用英文写,因为我也找不到类似的英文文章。以后没有完成的部分也会用英文。

可以转载,可以翻译,请标明原文出处。如果对原文有修改,请注明是你修改的。欢迎勘误。
1 楼 garfileo 2010-01-05  
话说这个有没有中文版,没有的话我翻了阿

相关推荐

Global site tag (gtag.js) - Google Analytics