Re: Unexpected Warning with g_object_new with boolean Properties
- From: Stefan Kost <kost imn htwk-leipzig de>
- To: Matt Sanchez <matt-sanchez comcast net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Unexpected Warning with g_object_new with boolean Properties
- Date: Wed, 15 Dec 2004 13:57:06 +0100
Hi Matt,
you dont need to supply a gvalue, doing just
o = g_object_new( test_get_type(), "test", TRUE, NULL );
will work.
Stefan
Matt Sanchez wrote:
When I call g_object_new and pass a boolean property as name,GValue *, I
get the following warning: GLib-GObject-WARNING **: value "TRUE" of type
`gboolean' is invalid or out of range for property `test' of type
`gboolean'.
Using the attached test code, I traced the problem to the
G_VALUE_COLLECT macro, which I have no real desire to fuss with. Is this
a real problem, or am I just missing the obvious?
I've tried this with glib-2.4.1, 2.4.6 and 2.4.8, on linux, all with the
same results.
Thanks,
Matt
-------------------------------------------------------------------------
/*
* test.c
*/
#include <glib-object.h>
#define TYPE_TEST (test_get_type())
#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_TEST, Test))
typedef struct _Test Test;
typedef struct _TestClass TestClass;
GType test_get_type( void );
struct _Test
{
GObject parent;
gboolean boolvalue;
};
struct _TestClass
{
GObjectClass parent;
};
static void
test_set_property( GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec )
{
Test * test = TEST( object );
switch( prop_id )
{
case 1:
test->boolvalue = g_value_get_boolean( value );
break;
default:
break;
}
}
static void
test_get_property( GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec )
{
Test * test = TEST( object );
switch( prop_id )
{
case 1:
g_value_set_boolean( value, test->boolvalue );
break;
default:
break;
}
}
static void
test_class_init( gpointer klass, gpointer data )
{
GObjectClass * gobject_class;
gobject_class = G_OBJECT_CLASS( klass );
gobject_class->set_property = test_set_property;
gobject_class->get_property = test_get_property;
g_object_class_install_property( gobject_class, 1,
g_param_spec_boolean( "test", "Test",
"Boolean property test", TRUE,
G_PARAM_READWRITE ) );
}
static void
test_instance_init( GTypeInstance * instance, gpointer klass )
{
Test * o = TEST( instance );
o->boolvalue = FALSE;
}
GType
test_get_type( void )
{
static GType test_type = 0;
if ( 0 == test_type )
{
static const GTypeInfo test_info =
{
sizeof( TestClass ), // class size
NULL, // base_init
NULL, // base_finalize
test_class_init, // class_init
NULL, // class_finalize
NULL, // class_data
sizeof( Test ), // instance size
0, // n_preallocs
test_instance_init, // instance_init
};
test_type = g_type_register_static( G_TYPE_OBJECT,
"Test", & test_info, 0 );
}
return test_type;
}
int main( int argc, char * argv[] )
{
GValue v = { 0, };
GObject * o;
g_type_init();
g_value_init( & v, G_TYPE_BOOLEAN );
g_value_set_boolean( & v, FALSE );
o = g_object_new( test_get_type(), "test", & v, NULL );
if ( o )
g_object_unref( o );
return 0;
}
-------------------------------------------------------------------------
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
--
\|/ Stefan Kost
<@ @> private business
+-oOO-(_)-OOo------------------------------------------------------ - - - - -
| __ Address Simildenstr. 5 HTWK Leipzig, Fb IMN, Postfach 301166
| /// 04277 Leipzig 04251 Leipzig
| __ /// Germany Germany
| \\\/// Phone +49341 2253538 +49341 30766101
| \__/ EMail st_kost_at_gmx.net kost_at_imn.htwk-leipzig.de
| WWW www.sonicpulse.de www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - - - -
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]