Jump to page: 1 2
Thread overview
GTKD2 GValue Type
Nov 19, 2014
Sergey
Nov 19, 2014
Kagamin
Nov 19, 2014
Sergey
Nov 19, 2014
Kagamin
Nov 19, 2014
Sergey
Nov 19, 2014
Kagamin
Nov 19, 2014
Kagamin
Nov 19, 2014
Marc Schütz
Nov 19, 2014
ketmar
Nov 19, 2014
Marc Schütz
Nov 19, 2014
ketmar
Nov 19, 2014
Mike Wey
Nov 20, 2014
Sergey
Nov 20, 2014
Sergey
November 19, 2014
    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.
November 19, 2014
Try to see what members GValue has, then it should be obvious.
November 19, 2014
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)
?
November 19, 2014
If they are documented, see docs, otherwise see source.
November 19, 2014
Also examples and unittests can show, how to use it.
November 19, 2014
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]
November 19, 2014
Why would you look for source of setValuesv when you don't know how to create GValue in the first place?
November 19, 2014
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.
November 19, 2014
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.


November 19, 2014
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?
« First   ‹ Prev
1 2