Re: [GObject, long] Gtype for enum + runtime init or by init function.

Dnia 22-06-2005, Åro o godzinie 18:25 -0400, Tristan Van Berkom
Uzytkownik wrote:

     You should start off by reading:

1. In g_param_spec_enum I must have GType of this enum.
a) Why this function need it?

Its needed to register metadata about the enum type
to the type system, furthermore the object will refuse
invalid values for the said enum.

b) How create for enum GType?

Copy paste from my code:

=========== header file ===========
enum GtkTtScrollTypeEnum {

#define MY_PACKAGE_ENUM_TYPE  (my_package_enum_type ())

GType gtktt_scroll_type (void);

============= source file ==============
gtktt_scroll_type (void)
     static GType etype = 0;
     if (etype == 0) {
         static const GEnumValue values[] = {
             { GTKTT_SCROLL_JUMPY,   "GTKTT_SCROLL_JUMPY",  "jumpy"   },
             { GTKTT_SCROLL_CATCH,   "GTKTT_SCROLL_CATCH",  "catch"   },
             { 0, NULL, NULL }
         etype = g_enum_register_static ("GtkTtScrollType", values);
     return etype;


2. I should register GType in package_name_get_type or

You must register the GType in the _get_type().
(if the type is not registered, then the type system didnt
get your GTypeInfo struct holding the pointer to the
_class_init function).

So, g_object_new (my_package_get_type())
will construct the object using the information stored
in the type system which was registered in my_package_get_type()
the first time it was called.


I know.
I thinking about something else (don't checking in runtime if it is
initialised, but in _init() function caller at begining).


Linux user: #376500 (patrz

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]