Re: How to use Glib::Value?



Replace
   data.init(G_TYPE_DATE_TIME);
by
   data.init(data.value_type());
or

   data.init(Glib::Value<Glib::DateTime>::value_type());

You don't store a GDateTime, you store a Glib::DateTime. That's not the same thing.

This is not well described in the documentation, but there is an example at
https://gitlab.gnome.org/GNOME/glibmm/blob/master/tests/glibmm_value/main.cc

On 2019-03-04 14:05, Pavlo Solntsev via gtkmm-list wrote:
Hi,

Have this code 
```
Glib::Value<int> datai;
datai.init(G_TYPE_INT);
datai.set(8);
std::cout << "Value = " << datai.get() << std::endl;
```
I see in stdout:
Value = 8

Works good. Now I would like to use another type: Glib::DateTime
```
Glib::Value<Glib::DateTime> data;

data.init(G_TYPE_DATE_TIME);
Glib::DateTime ctime = Glib::DateTime::create_now_utc();
data.set(ctime);
```

This compiles ok, but generates 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b2405c in Glib::DateTime::operator= (this=0x0, src="" at
/home/pavlo/jhbuild/checkout/glibmm-2.4/glib/glibmm/datetime.cc:89
89	  if(gobject_)



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