[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

TreeWidgetItem problem

Miquel Oliete

5/17/2007 9:50:00 AM

Hi there

I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
aboutQt() info).

This is my code.

@tree = Qt::TreeWidget.new(self)
self.setCentralWidget(@tree)

@rootItem = Qt::TreeWidgetItem.new(@tree)
@rootItem.setText(0, "Root")

0.upto(10) do |index|
item = Qt::TreeWidgetItem.new(@rootItem)
item.setText(0, "Node#{index}")
end

The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
tells me:

unresolved constructor call Qt::TreeWidgetItem (ArgumentError)

and reading Qt documentation there are two constructors allowed:

QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )

The first one is used in the @rootNode object creation and the second
one is the one which produces this message.

Can anybody help me?

Thanks in advance

Best regards


Miquel

5 Answers

Stefano Crocco

5/17/2007 10:02:00 AM

0

Alle giovedì 17 maggio 2007, Miquel ha scritto:
> Hi there
>
> I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
> aboutQt() info).
>
> This is my code.
>
> @tree = Qt::TreeWidget.new(self)
> self.setCentralWidget(@tree)
>
> @rootItem = Qt::TreeWidgetItem.new(@tree)
> @rootItem.setText(0, "Root")
>
> 0.upto(10) do |index|
> item = Qt::TreeWidgetItem.new(@rootItem)
> item.setText(0, "Node#{index}")
> end
>
> The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
> tells me:
>
> unresolved constructor call Qt::TreeWidgetItem (ArgumentError)
>
> and reading Qt documentation there are two constructors allowed:
>
> QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
> QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )
>
> The first one is used in the @rootNode object creation and the second
> one is the one which produces this message.
>
> Can anybody help me?
>
> Thanks in advance
>
> Best regards
>
>
> Miquel

It seems that you need to specify also the optional parameter. If you
substitute the line
item = Qt::TreeWidgetItem.new(@rootItem)
with
item = Qt::TreeWidgetItem.new(@rootItem, Qt::TreeWidgetItem::Type)
it should work (at least, it does on my system, with qt 4.2.3).

I hope this helps

Stefano

Miquel Oliete

5/17/2007 10:14:00 AM

0

En/na Stefano Crocco ha escrit:
> Alle giovedì 17 maggio 2007, Miquel ha scritto:
>
>> Hi there
>>
>> I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
>> aboutQt() info).
>>
>> This is my code.
>>
>> @tree = Qt::TreeWidget.new(self)
>> self.setCentralWidget(@tree)
>>
>> @rootItem = Qt::TreeWidgetItem.new(@tree)
>> @rootItem.setText(0, "Root")
>>
>> 0.upto(10) do |index|
>> item = Qt::TreeWidgetItem.new(@rootItem)
>> item.setText(0, "Node#{index}")
>> end
>>
>> The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
>> tells me:
>>
>> unresolved constructor call Qt::TreeWidgetItem (ArgumentError)
>>
>> and reading Qt documentation there are two constructors allowed:
>>
>> QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
>> QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )
>>
>> The first one is used in the @rootNode object creation and the second
>> one is the one which produces this message.
>>
>> Can anybody help me?
>>
>> Thanks in advance
>>
>> Best regards
>>
>>
>> Miquel
>>
>
> It seems that you need to specify also the optional parameter. If you
> substitute the line
> item = Qt::TreeWidgetItem.new(@rootItem)
> with
> item = Qt::TreeWidgetItem.new(@rootItem, Qt::TreeWidgetItem::Type)
> it should work (at least, it does on my system, with qt 4.2.3).
>
> I hope this helps
>
> Stefano
>
>
>
Hey, it is :-D !!!!!! but...Why isn't it necessary in the root node
creation (the constructor have the same optional parameter)?

Thanks


Miquel

Stefano Crocco

5/17/2007 11:00:00 AM

0

Alle giovedì 17 maggio 2007, Miquel ha scritto:
> En/na Stefano Crocco ha escrit:
> > Alle giovedì 17 maggio 2007, Miquel ha scritto:
> >> Hi there
> >>
> >> I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
> >> aboutQt() info).
> >>
> >> This is my code.
> >>
> >> @tree = Qt::TreeWidget.new(self)
> >> self.setCentralWidget(@tree)
> >>
> >> @rootItem = Qt::TreeWidgetItem.new(@tree)
> >> @rootItem.setText(0, "Root")
> >>
> >> 0.upto(10) do |index|
> >> item = Qt::TreeWidgetItem.new(@rootItem)
> >> item.setText(0, "Node#{index}")
> >> end
> >>
> >> The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
> >> tells me:
> >>
> >> unresolved constructor call Qt::TreeWidgetItem (ArgumentError)
> >>
> >> and reading Qt documentation there are two constructors allowed:
> >>
> >> QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
> >> QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )
> >>
> >> The first one is used in the @rootNode object creation and the second
> >> one is the one which produces this message.
> >>
> >> Can anybody help me?
> >>
> >> Thanks in advance
> >>
> >> Best regards
> >>
> >>
> >> Miquel
> >
> > It seems that you need to specify also the optional parameter. If you
> > substitute the line
> > item = Qt::TreeWidgetItem.new(@rootItem)
> > with
> > item = Qt::TreeWidgetItem.new(@rootItem, Qt::TreeWidgetItem::Type)
> > it should work (at least, it does on my system, with qt 4.2.3).
> >
> > I hope this helps
> >
> > Stefano
>
> Hey, it is :-D !!!!!! but...Why isn't it necessary in the root node
> creation (the constructor have the same optional parameter)?
>
> Thanks
>
>
> Miquel

Looking at the Korudum forum
(http://rubyforge.org/forum/forum.php?fo...), it seems there are some
situations in which QtRuby fails to correctly resolve overloaded methods. In
this case, the constructor which takes a Qt::ListWidget is resolved
correctly, the other isn't. A similar situation occurred me using
Qt::MessageBox.question. Although the documentation says the buttons and
defaultButton parameters are optional, the method call failed in ruby unless
they were both specified. Another example is mentioned on this thread of the
Korundum forum: http://rubyforge.org/forum/message.php?ms...

Stefano



Miquel Oliete

5/17/2007 11:07:00 AM

0

En/na Stefano Crocco ha escrit:
> Alle giovedì 17 maggio 2007, Miquel ha scritto:
>
>> En/na Stefano Crocco ha escrit:
>>
>>> Alle giovedì 17 maggio 2007, Miquel ha scritto:
>>>
>>>> Hi there
>>>>
>>>> I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
>>>> aboutQt() info).
>>>>
>>>> This is my code.
>>>>
>>>> @tree = Qt::TreeWidget.new(self)
>>>> self.setCentralWidget(@tree)
>>>>
>>>> @rootItem = Qt::TreeWidgetItem.new(@tree)
>>>> @rootItem.setText(0, "Root")
>>>>
>>>> 0.upto(10) do |index|
>>>> item = Qt::TreeWidgetItem.new(@rootItem)
>>>> item.setText(0, "Node#{index}")
>>>> end
>>>>
>>>> The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
>>>> tells me:
>>>>
>>>> unresolved constructor call Qt::TreeWidgetItem (ArgumentError)
>>>>
>>>> and reading Qt documentation there are two constructors allowed:
>>>>
>>>> QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
>>>> QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )
>>>>
>>>> The first one is used in the @rootNode object creation and the second
>>>> one is the one which produces this message.
>>>>
>>>> Can anybody help me?
>>>>
>>>> Thanks in advance
>>>>
>>>> Best regards
>>>>
>>>>
>>>> Miquel
>>>>
>>> It seems that you need to specify also the optional parameter. If you
>>> substitute the line
>>> item = Qt::TreeWidgetItem.new(@rootItem)
>>> with
>>> item = Qt::TreeWidgetItem.new(@rootItem, Qt::TreeWidgetItem::Type)
>>> it should work (at least, it does on my system, with qt 4.2.3).
>>>
>>> I hope this helps
>>>
>>> Stefano
>>>
>> Hey, it is :-D !!!!!! but...Why isn't it necessary in the root node
>> creation (the constructor have the same optional parameter)?
>>
>> Thanks
>>
>>
>> Miquel
>>
>
> Looking at the Korudum forum
> (http://rubyforge.org/forum/forum.php?fo...), it seems there are some
> situations in which QtRuby fails to correctly resolve overloaded methods. In
> this case, the constructor which takes a Qt::ListWidget is resolved
> correctly, the other isn't. A similar situation occurred me using
> Qt::MessageBox.question. Although the documentation says the buttons and
> defaultButton parameters are optional, the method call failed in ruby unless
> they were both specified. Another example is mentioned on this thread of the
> Korundum forum: http://rubyforge.org/forum/message.php?ms...
>
> Stefano
>
>
>
>
>
Ok, I have reported this issue to the KDE bindings list and Richard Dale
is asking me some questions. If you are interested in final conclusions
I'll post here :-D

Thanks for all

Best regards

Miquel

richard.j.dale@gmail.com

5/17/2007 3:53:00 PM

0

On May 17, 11:01 am, Stefano Crocco <stefano.cro...@alice.it> wrote:
> Alle gioved? 17 maggio 2007, Miquel ha scritto:
>
>
>
> > Hi there
>
> > I'm trying to code a Tree using ruby qt bindings (Qt v4.2.0 using
> > aboutQt() info).
>
> > This is my code.
>
> > @tree = Qt::TreeWidget.new(self)
> > self.setCentralWidget(@tree)
>
> > @rootItem = Qt::TreeWidgetItem.new(@tree)
> > @rootItem.setText(0, "Root")
>
> > 0.upto(10) do |index|
> > item = Qt::TreeWidgetItem.new(@rootItem)
> > item.setText(0, "Node#{index}")
> > end
>
> > The problem is in 'item = Qt::TreeWidgetItem.new(@rootItem)', system
> > tells me:
>
> > unresolved constructor call Qt::TreeWidgetItem (ArgumentError)
>
> > and reading Qt documentation there are two constructors allowed:
>
> > QTreeWidgetItem ( QTreeWidget * parent, int type = Type )
> > QTreeWidgetItem ( QTreeWidgetItem * parent, int type = Type )
>
> > The first one is used in the @rootNode object creation and the second
> > one is the one which produces this message.
>
> > Can anybody help me?
>
> > Thanks in advance
>
> > Best regards
>
> > Miquel
>
> It seems that you need to specify also the optional parameter. If you
> substitute the line
> item = Qt::TreeWidgetItem.new(@rootItem)
> with
> item = Qt::TreeWidgetItem.new(@rootItem, Qt::TreeWidgetItem::Type)
> it should work (at least, it does on my system, with qt 4.2.3).
I've found out what the problem is, and it's already fixed in the kde
svn version of QtRuby. Here is the entry from the ChangeLog:

2006-12-16 Richard Dale <rdale@xxxx>

* There is no way to distinguish between the two constructors:
QTreeWidgetItem (const QTreeWidgetItem & other)
QTreeWidgetItem (QTreeWidgetItem * parent, const QStringList &
strings, int type = Type)
when the latter has a single argument. So force the second variant
to
be called

-- Richard