www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - GTKD2 GValue Type

reply "Sergey" <httpal gmail.com> writes:
     Hello everyone!

I try to use gtkd + d in production, and of course I started with 
gtk.TreeView and gtk.ListStore objects. But I encounter a problem 
with GValyue type:

GValue[] array_values = 
cast(GValue[])["str1","str2","str3","str4"];
file_1.d(92): Error: e2ir: cannot cast "str1" of type string to 
type GValue
...

ListStore1.setValuesv(itr, [0,1,2,3], 
"str1","str2","str3","str4");
file_1.d(98): Error: function gtk.ListStore.ListStore.setValuesv 
(TreeIter iter, int[] columns, GValue[] values) is not callable 
using argument types (TreeIter, int[], string, string, string, 
string)

GValue ggg = cast(GValue)"123";
file_1.d(78): Error: cannot cast from string to GValue

GValue ggg = "123";
file_1.d(79): Error: cannot implicitly convert expression ("123") 
of type string to GValue

How to deal with this type?

thanks in advance.
Nov 18 2014
next sibling parent reply "Kagamin" <spam here.lot> writes:
Try to see what members GValue has, then it should be obvious.
Nov 18 2014
parent reply "Sergey" <httpal gmail.com> writes:
On Wednesday, 19 November 2014 at 07:34:45 UTC, Kagamin wrote:
 Try to see what members GValue has, then it should be obvious.
How to do it? GValue ggg; writeln(ggg); answer: GValue(INVALID, Data, Data) ?
Nov 18 2014
next sibling parent reply "Kagamin" <spam here.lot> writes:
If they are documented, see docs, otherwise see source.
Nov 19 2014
parent reply "Sergey" <httpal gmail.com> writes:
On Wednesday, 19 November 2014 at 08:25:59 UTC, Kagamin wrote:
 If they are documented, see docs, otherwise see source.
source: /** * A variant of gtk_list_store_set_valist() which * takes the columns and values as two arrays, instead of * varargs. This function is mainly intended for * language-bindings and in case the number of columns to * change is not known until run-time. * Since 2.12 * Params: * iter = A valid GtkTreeIter for the row being modified * columns = an array of column numbers. [array length=n_values] * values = an array of GValues. [array length=n_values] */ public void setValuesv(TreeIter iter, int[] columns, GValue[] values) { // void gtk_list_store_set_valuesv (GtkListStore *list_store, GtkTreeIter *iter, gint *columns, GValue *values, gint n_values); gtk_list_store_set_valuesv(gtkListStore, (iter is null) ? null : iter.getTreeIterStruct(), columns.ptr, values.ptr, cast(int) columns.length); } ************************************************* DOC: void setValuesv (TreeIter iter, int[] columns, GValue[] values); A variant of gtk_list_store_set_valist() which takes the columns and values as two arrays, instead of varargs. This function is mainly intended for language-bindings and in case the number of columns to change is not known until run-time. Since 2.12 Params: TreeIter iter A valid GtkTreeIter for the row being modified int[] columns an array of column numbers. [array length=n_values] GValue[] values an array of GValues. [array length=n_values]
Nov 19 2014
parent "Kagamin" <spam here.lot> writes:
Why would you look for source of setValuesv when you don't know 
how to create GValue in the first place?
Nov 19 2014
prev sibling parent "Kagamin" <spam here.lot> writes:
Also examples and unittests can show, how to use it.
Nov 19 2014
prev sibling next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Wednesday, 19 November 2014 at 02:50:40 UTC, Sergey wrote:
     Hello everyone!

 I try to use gtkd + d in production, and of course I started 
 with gtk.TreeView and gtk.ListStore objects. But I encounter a 
 problem with GValyue type:

 GValue[] array_values = 
 cast(GValue[])["str1","str2","str3","str4"];
 file_1.d(92): Error: e2ir: cannot cast "str1" of type string to 
 type GValue
 ...

 ListStore1.setValuesv(itr, [0,1,2,3], 
 "str1","str2","str3","str4");
 file_1.d(98): Error: function 
 gtk.ListStore.ListStore.setValuesv (TreeIter iter, int[] 
 columns, GValue[] values) is not callable using argument types 
 (TreeIter, int[], string, string, string, string)

 GValue ggg = cast(GValue)"123";
 file_1.d(78): Error: cannot cast from string to GValue

 GValue ggg = "123";
 file_1.d(79): Error: cannot implicitly convert expression 
 ("123") of type string to GValue

 How to deal with this type?

 thanks in advance.
D doesn't allow construction from a different type with the `Type name = value;` syntax. Try this: GValue ggg = GValue("123"); // or shorter: auto ggg = GValue("123"); Haven't tested this, though.
Nov 19 2014
parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, 19 Nov 2014 12:33:17 +0000
via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 D doesn't allow construction from a different type with the `Type=20
 name =3D value;` syntax. Try this:
har-har... here comes the power of the dark side! struct S { bool filler; // just in case, to avoid S("str") string s; disable this (); // just in case too this (string v) { s =3D "s|"~v; } this (int v) { import std.conv : to; s =3D "i|"~to!string(v); } this (double v) { import std.conv : to; s =3D "d|"~to!string(v); } string toString () const nothrow nogc { return s; } } void main () { import std.stdio; S s0 =3D "string"; S s1 =3D 42; S s2 =3D 666.0; writeln(s0); // writes "s|string" writeln(s1); // writes "i|42" writeln(s2); // writes "d|666" } and remember, we have cookies.
Nov 19 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Wednesday, 19 November 2014 at 13:31:16 UTC, ketmar via 
Digitalmars-d wrote:
 On Wed, 19 Nov 2014 12:33:17 +0000
 via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 D doesn't allow construction from a different type with the 
 `Type name = value;` syntax. Try this:
har-har... here comes the power of the dark side! struct S { bool filler; // just in case, to avoid S("str") string s; disable this (); // just in case too this (string v) { s = "s|"~v; } this (int v) { import std.conv : to; s = "i|"~to!string(v); } this (double v) { import std.conv : to; s = "d|"~to!string(v); } string toString () const nothrow nogc { return s; } } void main () { import std.stdio; S s0 = "string"; S s1 = 42; S s2 = 666.0; writeln(s0); // writes "s|string" writeln(s1); // writes "i|42" writeln(s2); // writes "d|666" } and remember, we have cookies.
Ah, right, it _does_ work with explicitly defined constructors. Maybe GValue doesn't have those?
Nov 19 2014
parent ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, 19 Nov 2014 13:44:09 +0000
via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 Ah, right, it _does_ work with explicitly defined constructors.=20
 Maybe GValue doesn't have those?
that may be true. i'm too lazy to look at the sources, and it seems to me that it's very easy to miss the fact that adding explicit constructors will allow to construct struct with simple assign, so authors seems to omit such constructors (and adding 'setXXX' functions, heh ;-).
Nov 19 2014
prev sibling parent reply Mike Wey <mike-wey example.com> writes:
On 11/19/2014 03:50 AM, Sergey wrote:
      Hello everyone!

 I try to use gtkd + d in production, and of course I started with
 gtk.TreeView and gtk.ListStore objects. But I encounter a problem with
 GValyue type:

 GValue[] array_values = cast(GValue[])["str1","str2","str3","str4"];
 file_1.d(92): Error: e2ir: cannot cast "str1" of type string to type GValue
 ...

 ListStore1.setValuesv(itr, [0,1,2,3], "str1","str2","str3","str4");
 file_1.d(98): Error: function gtk.ListStore.ListStore.setValuesv
 (TreeIter iter, int[] columns, GValue[] values) is not callable using
 argument types (TreeIter, int[], string, string, string, string)

 GValue ggg = cast(GValue)"123";
 file_1.d(78): Error: cannot cast from string to GValue

 GValue ggg = "123";
 file_1.d(79): Error: cannot implicitly convert expression ("123") of
 type string to GValue

 How to deal with this type?

 thanks in advance.
If it's really just strings you can use; ListStore1.setValues(itr, [0,1,2,3], ["str1","str2","str3","str4"]); Otherwise you'll need to make multiple calls to ListStore.setValue. For setValuesv there is an error in the generated code it should except an array of gobject.Value, in stead of the the C equivalent. -- Mike Wey
Nov 19 2014
parent reply "Sergey" <httpal gmail.com> writes:
Ok, thanks. I'll just use this command:
ListStore1.setValue(itr, 0, "some str");
...
Nov 19 2014
parent "Sergey" <httpal gmail.com> writes:
auto ggg = GValue("123");
file_12.d(27): Error: cannot implicitly convert expression 
("123") of type string to GType


GValue ggg = {"ki",};
file_12.d(22): Error: cannot implicitly convert expression ("ki") 
of type string to GType
Nov 19 2014