Qtruby and the ListViewItemIterator

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 methodoperator’ 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)

Nigel W. wrote:

puts it.operator++()
/mainform.ui.rb:33:in method_missing': undefined methodoperator’ 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 F. wrote:

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

/mainform.ui.rb:33:in method_missing': undefined methodoperator’ 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

Vincent F. wrote:

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

/mainform.ui.rb:33:in method_missing': undefined methodoperator’ 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

On Sat, 18 Nov 2006 16:50:08 +0900
[email protected][email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs