From: "richard.j.dale@..." Date: 2006-11-21T03:25:05+09:00 Subject: Re: qtruby and the ListViewItemIterator 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 > > # (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