[Gtk-sharp-list] Gtk.SpinButton recursive signals create
segfault
Fabian Sturm
f@rtfs.org
Wed, 09 Mar 2005 00:49:19 +0100
--=-biFcWKmeYEofBksY8gXk
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi!
Hmm replying to myself is bad but I got lots of help in IRC, thanks for
that! And now I could nail down the problem a little bit.
I now produced a proper testcase which compiles and runs.
If you run it and click on the Spinbutton to increase the value you
will get a wrong value displayed.
Why is this so? What is a proper fix to this?
Thanks a lot, Fabian (being quite puzzled about this one)
--=-biFcWKmeYEofBksY8gXk
Content-Disposition: attachment; filename=spinbutton.cs
Content-Type: text/x-csharp; name=spinbutton.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
using Gtk;
using System;
public class MainClass
{
public delegate void EventHandler (object o);
// This class holds all data
public class Data
{
public event EventHandler Changed;
private int num;
public int Num {
get { return num; }
set { if (num != value) { num = value; OnChanged (); } }
}
// methods
protected void OnChanged ()
{
if (Changed != null) {
Changed (this);
}
}
}
// This class generates a gui displaying the data
public class Gui
{
private Data d;
private SpinButton sb;
public Gui (Data d)
{
Application.Init ();
this.d = d;
Window w = new Window ("MainWindow");
w.Show ();
sb = new SpinButton (0, 10, 1);
sb.Changed += on_spinbutton_changed;
w.Add (sb);
sb.Show ();
d.Changed += new EventHandler (OnDataChanged);
Application.Run ();
}
public void OnDataChanged (System.Object o)
{
sb.Value = d.Num;
}
// gtk# signal handler
public void on_spinbutton_changed (object o, EventArgs args)
{
Console.WriteLine ("Spinbutton changed");
d.Num = ((SpinButton)o).ValueAsInt;
}
}
public static void Main (string[] args)
{
Data d = new Data ();
Gui g = new Gui (d);
}
}
--=-biFcWKmeYEofBksY8gXk--