Creating new GObject



Hello.

I'm writing an Object from GObject. But when running my dummy app prints errors and nothing happens ;-)

Can someone look at my sources (they are dummy) and fix this problem (sources attached). It's a dummy Point (dot) class, nothing more ;-)

Error messages:

(process:8753): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function

(process:8753): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed

(process:8753): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
#include <glib-object.h>

#include "point.h"

int
main (int argc,
      char *argv[])
{
  Point *point;

  point = point_new ();

  //g_object_set (G_OBJECT (point), "x", 10, NULL);
  //g_object_set (G_OBJECT (point), "y", 10, NULL);

  return 0;
}

#include <glib-object.h>

#include "point.h"

enum {
  PROP_0,
  PROP_X,
  PROP_Y,
};

static void point_set_property (GObject         *object,
    		                guint            prop_id,
		                const GValue    *value,
		                GParamSpec      *pspec);

static void point_get_property (GObject         *object,
		                guint            prop_id,
		                GValue          *value,
		                GParamSpec      *pspec);

G_DEFINE_TYPE (Point, point, G_TYPE_OBJECT)

static void
point_class_init (PointClass *klass)
{
  GObjectClass *gobject_klass;

  gobject_klass = (GObjectClass*) klass;

  gobject_klass->set_property = point_set_property;
  gobject_klass->get_property = point_get_property;

  g_object_class_install_property (gobject_klass,
                                   PROP_X,
                                   g_param_spec_string ("x",
                                                        "x",
                                                        "X position",
                                                        NULL,
                                                        G_PARAM_READABLE |
							G_PARAM_WRITABLE));
  g_object_class_install_property (gobject_klass,
                                   PROP_Y,
                                   g_param_spec_string ("y",
                                                        "y",
                                                        "Y position",
                                                        NULL,
                                                        G_PARAM_READABLE |
							G_PARAM_WRITABLE));

}

static void
point_init (Point *point)
{
  point->x = 0;
  point->y = 0;
}

static void 
point_set_property (GObject         *object,
		    guint            prop_id,
		    const GValue    *value,
		    GParamSpec      *pspec)
{
  Point *point;

  point = POINT (object);

  switch (prop_id)
    {
    case PROP_X:
      point->x = g_value_get_int (value);
      break;
    case PROP_Y:
      point->y = g_value_get_int (value);
      break;
    default:      
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void 
point_get_property (GObject         *object,
		    guint            prop_id,
		    GValue          *value,
		    GParamSpec      *pspec)
{
  Point *point;

  point = POINT (object);

  switch (prop_id)
    {
    case PROP_X:
      g_value_set_int (value, point->x);
      break;
    case PROP_Y:
      g_value_set_int (value, point->y);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

Point*
point_new ()
{
  return g_object_new (TYPE_POINT, NULL);
}

#ifndef __GOBJECT_POINT_H__
#define __GOBJECT_POINT_H__

G_BEGIN_DECLS

#define TYPE_POINT                  (point_get_type ())
#define POINT(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_POINT, Point))
#define IS_POINT(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_POINT))

typedef struct _Point       Point;
typedef struct _PointClass  PointClass;

struct _Point
{
  GObject parent;

  gint x;
  gint y;
};

struct _PointClass
{
  GObjectClass parent_class;
};

Point*          point_new ();

G_END_DECLS

#endif /* __GOBJECT_POINT_H__ */


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