[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

qtruby and the ListViewItemIterator

Nigel Wilkinson

11/17/2006 9:14:00 PM

Hi folks

I'm trying qtruby out and have struck an issue I can't conquer.

I have a listview widget which is populated with listviewitems and want
to iterate through the whole lot.

The code snippet is

it = Qt::ListViewItemIterator.new(@listView)
puts it.operator++()

The "puts" is only there so I can see what's happening.

When I run the app I get the following all on one line (not 2 lines
as here):-

/mainform.ui.rb:33:in `method_missing': undefined method `operator' for
#<Qt::ListViewItemIterator:0xb6c08c24> (NoMethodError)

I'm useing the Trolltech API documentation and can't figure where I'm
messing up.

Thanks in advance
Frustrated of Heathfield (aka Nigel)

4 Answers

Vincent Fourmond

11/17/2006 9:42:00 PM

0

Nigel Wilkinson wrote:
> Hi folks
>
> I'm trying qtruby out and have struck an issue I can't conquer.
>
> I have a listview widget which is populated with listviewitems and want
> to iterate through the whole lot.
>
> The code snippet is
>
> it = Qt::ListViewItemIterator.new(@listView)
> puts it.operator++()

> /mainform.ui.rb:33:in `method_missing': undefined method `operator' for
> #<Qt::ListViewItemIterator:0xb6c08c24> (NoMethodError)

Well, the operator ++ is meant to be called directly ++ when written
in C++. In ruby, however, that won't work as ++ is not an operator.
You might want to try (untested):

p it.send(:'++')

Cheers !

Vince

--
Vincent Fourmond, PhD student
http://vincent.fourmon...

richard.j.dale@gmail.com

11/18/2006 7:48:00 AM

0


Vincent Fourmond wrote:
> Nigel Wilkinson wrote:
> > Hi folks
> >
> > I'm trying qtruby out and have struck an issue I can't conquer.
> >
> > I have a listview widget which is populated with listviewitems and want
> > to iterate through the whole lot.
> >
> > The code snippet is
> >
> > it = Qt::ListViewItemIterator.new(@listView)
> > puts it.operator++()
>
> > /mainform.ui.rb:33:in `method_missing': undefined method `operator' for
> > #<Qt::ListViewItemIterator:0xb6c08c24> (NoMethodError)
>
> Well, the operator ++ is meant to be called directly ++ when written
> in C++. In ruby, however, that won't work as ++ is not an operator.
> You might want to try (untested):
>
> p it.send(:'++')
No, that won't work. You need to use 'it += 1' instead in QtRuby:

irb(main):002:0> lv = Qt::ListView.new
=> #<Qt::ListView:0xb79e1dac name="unnamed", x=320, y=240, width=640,
height=320>
irb(main):003:0> item1 = Qt::ListViewItem.new(lv)
=> #<Qt::ListViewItem:0xb79dbe70>
irb(main):004:0> item2 = Qt::ListViewItem.new(lv)
=> #<Qt::ListViewItem:0xb79d8180>
irb(main):005:0> item3 = Qt::ListViewItem.new(lv)
=> #<Qt::ListViewItem:0xb79d3054>
irb(main):006:0> it = Qt::ListViewItemIterator.new(lv)
=> #<Qt::ListViewItemIterator:0xb79cf620>
irb(main):007:0> it.current
=> #<Qt::ListViewItem:0xb79d3054>
irb(main):008:0> it += 1
=> #<Qt::ListViewItemIterator:0xb79cf620>
irb(main):009:0> it.current
=> #<Qt::ListViewItem:0xb79dbe70>
irb(main):010:0> it += 1
=> #<Qt::ListViewItemIterator:0xb79cf620>
irb(main):011:0> it.current
=> #<Qt::ListViewItem:0xb79d8180>
irb(main):012:0> it += 1
=> #<Qt::ListViewItemIterator:0xb79cf620>
irb(main):013:0> it.current
=> nil


-- Richard

richard.j.dale@gmail.com

11/20/2006 6:23:00 PM

0

Vincent Fourmond wrote:
> Nigel Wilkinson wrote:
> > Hi folks
> >
> > I'm trying qtruby out and have struck an issue I can't conquer.
> >
> > I have a listview widget which is populated with listviewitems and want
> > to iterate through the whole lot.
> >
> > The code snippet is
> >
> > it = Qt::ListViewItemIterator.new(@listView)
> > puts it.operator++()
>
> > /mainform.ui.rb:33:in `method_missing': undefined method `operator' for
> > #<Qt::ListViewItemIterator:0xb6c08c24> (NoMethodError)
>
> Well, the operator ++ is meant to be called directly ++ when written
> in C++. In ruby, however, that won't work as ++ is not an operator.
> You might want to try (untested):
>
> p it.send(:'++')
That will nearly work, but the method is a C++ method in the Smoke
library, and so it is called 'operator++':

mardigras rdale 504% rbqt3api Qt::ListViewItemIterator |grep operator
QListViewItem* QListViewItemIterator::operator*()
QListViewItemIterator& QListViewItemIterator::operator++()
const QListViewItemIterator
QListViewItemIterator::operator++(int)
QListViewItemIterator& QListViewItemIterator::operator+=(int)
QListViewItemIterator& QListViewItemIterator::operator--()
const QListViewItemIterator
QListViewItemIterator::operator--(int)
QListViewItemIterator& QListViewItemIterator::operator-=(int)
QListViewItemIterator& QListViewItemIterator::operator=(const
QListViewItemI

Instead you need to do something like this:

p it.send("operator++".to_sym)

I've just added some each methods to various Qt3 QtRuby classes, and
made them enumerable, so you no longer need to use an external C++
style iterator with them. This is the comment from the ChangeLog:

* Made Qt::ListView, Qt::ListViewItem, Qt::BoxLayout, Qt::HBoxLayout,
Qt::VBoxLayout and Qt::GridLayout Enumerable with implementations
of each() so they don't need to use the Qt External iterators like
Qt::LayoutIterator anymore. For instance:

lv = Qt::ListView.new do
["one", "two", "three", "four"].each do |label|
Qt::ListViewItem.new(self, label, "zzz")
end
end

lv.each do |item|
p item.inspect
pp item.inspect
end

* Add inspect() and pretty_print() methods to Qt::ListViewItem so that
they show the text of their columns

The improvements will be in the next release of Qt3 QtRuby.

-- Richard

Nigel Wilkinson

11/22/2006 7:23:00 PM

0

On Sat, 18 Nov 2006 16:50:08 +0900
"richard.j.dale@gmail.com" <richard.j.dale@gmail.com> wrote:

>
> Vincent Fourmond wrote:
> > Nigel Wilkinson wrote:
> > > Hi folks
> > >
> > > I'm trying qtruby out and have struck an issue I can't conquer.
> > >
> > > I have a listview widget which is populated with listviewitems
> > > and want to iterate through the whole lot.
> > >
> > > The code snippet is
> > >
> > > it = Qt::ListViewItemIterator.new(@listView)
> > > puts it.operator++()
> >
> > Well, the operator ++ is meant to be called directly ++ when
> > written in C++. In ruby, however, that won't work as ++ is not an
> > operator. You might want to try (untested):
> >
> > p it.send(:'++')
> No, that won't work. You need to use 'it += 1' instead in QtRuby:

That works for me - thanks very much

Nigel