Sign up

Entry from ComboBoxText

I'm trying to get the Entry from a ComboBoxText as I need it to show text which is not in the list, calling setActiveText just sets the Entry to the first item. I tried the following code, but am getting a Seg Fault, on the cast to Entry, what am I doing wrong?

When I look at it with a debugger, widget looks like a valid object. The GTK docs say to use gtkbinget_child which is what the getChild is doing in Bin.d.

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = cast(Entry) widget;
	entry.setText(dialog.getFilename());
}

Re: Entry from ComboBoxText

On 11/12/2015 08:20 PM, Gerald Nunn wrote:

I'm trying to get the Entry from a ComboBoxText as I need it to show text which is not in the list, calling setActiveText just sets the Entry to the first item. I tried the following code, but am getting a Seg Fault, on the cast to Entry, what am I doing wrong?

When I look at it with a debugger, widget looks like a valid object. The GTK docs say to use gtkbinget_child which is what the getChild is doing in Bin.d.

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = cast(Entry) widget;
	entry.setText(dialog.getFilename());
}

As a workaround the following should work:

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = new Entry(widget.getWidgetStruct());
	entry.setText(dialog.getFilename());
}

Re: Entry from ComboBoxText

On Thu, 12 Nov 2015 23:07:20 +0100, Mike Wey wrote:

As a workaround the following should work:

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = new Entry(widget.getWidgetStruct());
	entry.setText(dialog.getFilename());
}

Thanks Mike, I had to make one small change to case the entry struct to GtkEntry as per the code below and it worked fine. Might be nice to include a convenience function in the future for this though I see gtk itself doesn't exactly make this intuitive either.

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = new Entry(cast(GtkEntry*)widget.getWidgetStruct());
	entry.setText(dialog.getFilename());
}

Re: Entry from ComboBoxText

On Thu, 12 Nov 2015 19:20:59 GMT, Gerald Nunn wrote:

I'm trying to get the Entry from a ComboBoxText as I need it to show text which is not in the list, calling setActiveText just sets the Entry to the first item. I tried the following code, but am getting a Seg Fault, on the cast to Entry, what am I doing wrong?

When I look at it with a debugger, widget looks like a valid object. The GTK docs say to use gtkbinget_child which is what the getChild is doing in Bin.d.

Widget widget = cbPath.getChild();
if (widget !is null) {
	Entry entry = cast(Entry) widget;
	entry.setText(dialog.getFilename());
}

For anyone running into this now (ie. post-May 2019) the above cast() now works. Thanks to all the guys (probably just Mike) who keep GtkD up to date.