qtruby and the ListViewItemIterator

Discussion in 'Ruby' started by Nigel Wilkinson, Nov 17, 2006.

  1. 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)
     
    Nigel Wilkinson, Nov 17, 2006
    #1
    1. Advertising

  2. 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.fourmond.neuf.fr/
     
    Vincent Fourmond, Nov 17, 2006
    #2
    1. Advertising

  3. Nigel Wilkinson

    Guest

    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
     
    , Nov 18, 2006
    #3
  4. Nigel Wilkinson

    Guest

    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::eek:perator*()
    QListViewItemIterator& QListViewItemIterator::eek:perator++()
    const QListViewItemIterator
    QListViewItemIterator::eek:perator++(int)
    QListViewItemIterator& QListViewItemIterator::eek:perator+=(int)
    QListViewItemIterator& QListViewItemIterator::eek:perator--()
    const QListViewItemIterator
    QListViewItemIterator::eek:perator--(int)
    QListViewItemIterator& QListViewItemIterator::eek:perator-=(int)
    QListViewItemIterator& QListViewItemIterator::eek:perator=(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
     
    , Nov 20, 2006
    #4
  5. On Sat, 18 Nov 2006 16:50:08 +0900
    "" <> 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
     
    Nigel Wilkinson, Nov 22, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jochen Immendörfer

    qtruby and ms windows

    Jochen Immendörfer, Jul 14, 2004, in forum: Ruby
    Replies:
    1
    Views:
    115
    Alexander Kellett
    Jul 14, 2004
  2. Bauduin Raphael

    QtRuby and use of .ui files

    Bauduin Raphael, Sep 24, 2004, in forum: Ruby
    Replies:
    1
    Views:
    613
    Richard Dale
    Sep 25, 2004
  3. Hans  Fugal
    Replies:
    4
    Views:
    164
    Hans Fugal
    Oct 19, 2005
  4. gnufied

    inheritance and Qtruby

    gnufied, Apr 25, 2006, in forum: Ruby
    Replies:
    1
    Views:
    112
  5. Fredrik J

    Qtruby and Qwt

    Fredrik J, Jan 18, 2007, in forum: Ruby
    Replies:
    0
    Views:
    158
    Fredrik J
    Jan 18, 2007
Loading...

Share This Page