[Kde-bindings] QComboBox and QListBoxItem

Richard Dale Richard_Dale at tipitina.demon.co.uk
Sun Apr 4 08:45:46 UTC 2004


On Saturday 03 April 2004 17:36, Imobach González Sosa wrote:
> El Sábado 03 Abril 2004 13:51, Richard Dale escribió:
> > I've had a look for examples of Qt::ComboBox, and the tictac one creates
> > a combo box like this:
> >
> >                 # Create the combo box for deciding who should start
> >                 # and connect its clicked() signals to the
> > buttonClicked() slot @whoStarts = Qt::ComboBox.new(self)
> >                 @whoStarts.insertItem('Computer starts')
> >                 @whoStarts.insertItem('Human starts')
> >                 l.addWidget(@whoStarts);
> >
> > So it doesn't create a seperate Qt::ListBoxItems like you do, but adds
> > the list of things directly to the ComboBox with the insertItem() method.
>
> Yes, that's right. But I forgot to mention in my post that I need to use
> ListBoxItems. Why? I need a value associated to each item of the combo,
> just like 'value' when using the tag <SELECT> in HTML. Do you know?
>
> So, I thought that I could create a new class which inherited from
> ListBoxItem (let's call ListBoxItemExtended), adding this value. Then,
> putting some ListBoxItemExtended objects into a QListBox and getting this
> list into de QComboBox could do the trick.
>
> >    @combo = Qt::ComboBox.new(false, centralWidget(), "@combo")
> >    @combo.setGeometry( Qt::Rect.new(20, 59, 105, 33) )
> >    @combo.insertItem("oranges")
> >
> > Alternatively, I think Qt::ComboBox.setListBox() resets everything, so
> > you might need to do that first rather than last, and it might work.
>
> Yes, I tried that too but it didn't work.
I think your custom ListBoxItem's might be being garbage collected as there 
are no ruby instances. The actual C++ instance isn't deleted because it is 
still owned by the QListBox. But when you subsequently refer to that instance 
a new ruby 'wrapper' instance is created which isn't an instance of 
ListBoxItemExtended.

Maybe a partial fix would be to add the ListBoxItemExtended items to a ruby 
Array to ensure that ruby doesn't garbage collect them. If it works after 
that, it would confirm what the problem was.

-- Richard



More information about the Kde-bindings mailing list