From: Stefano Crocco Date: 2012-09-01T21:13:28+09:00 Subject: Re: Qt signals driving me crazy On Saturday 01 September 2012 Damjan Rems wrote > Stefano was right. It works now. I must have lost my nerves somewhere in > beetween ;-( The problem is that all three declarations must be the > same: > > slots 'nitem_clicked(QTreeWidgetItem*, int)' > > connect(self, SIGNAL('itemActivated( QTreeWidgetItem*, int )'), > self, SLOT('nitem_clicked(QTreeWidgetItem*, int)')) > > Thanks guys. > ---------------------- > > Now I have another problem. You can add text and icons to > Qt::TreeWidgetItem. > > item = Qt::TreeWidgetItem.new > item.setText(0,'Test') > item.setIcon(0, Qt::Icon.new('pics/test.png') ) > > But I would like to add an object. There is a method > QTreeWidgetItem::setData ( int column, int role, const QVariant & value > ) > > If I use item.setData(0, Qt::UserRole, some_object) I get > method_missing': undefined method `setData ... > > which usually means that one of data type is not valid. Is there another > way to add object pointer to QTreeWidgetItem. > > by > TheR > > -- > Posted via http://www.ruby-forum.com/. setData requires s Qt::Variant as last argument, not a ruby object. In theory, with sufficiently recent version of QtRuby, you should be able to create a Qt::Variant from any ruby object using Qt::Variant.from_value my_obj When I tried it, however, I found out that it sometimes caused crashes. There should also be another way to do so, which I haven't tried. Look at the first example at http://techbase.kde.org/Development/Languages/Ruby#Emitting_Ruby_Classes If these methods don't work for you, your only option is to somehow create a string or number or something else which you can put in a Qt::Variant and which allows you to identify the object (the object_id of the object itself could be a good candidate). I hope this helps Stefano