Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Value

The GObject::Value (aliased as just peel::Value for short) shows up a lot less in C++ code using peel compared to the frequency of GValue in plain C code (this is in no small part because of peel implementing the get_property and set_property vfuncs automatically). Still, it plays an important role in various APIs.

To create a new value, define a variable of type Value (on the stack) and initialize it by passing the type that it’s going to hold:

#include <peel/GObject/Value.h>

using namespace peel;

Value value { Type::of<int> () };

To get and set the value, use the method templates get and set:

#include <peel/GObject/Value.h>

using namespace peel;

Value value { Type::of<int> () };
value->set<int> (42);
int fourty_two = value->get<int> ();

The template type argument used here