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 [url]http://www.gtk.org/[/url].


-- 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 [url]http://www.gtk.org/[/url]. 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:
[quote]gcc `pkg-config --cflags --libs gobject-2.0` example.c -o example[/quote]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值