From: Ken Bloom Date: 2009-08-05T08:08:20+09:00 Subject: Re: QtRuby Questions: Why does On Wed, 05 Aug 2009 06:50:22 +0900, Matthew Borgeson wrote: > My current goal is to simply have the lineEdit3 field "automagically" > display the word "fudge" whenever a number is simply entered into > lineEdit1, I have looked at the Rapid GUI Development Fridays book, The > Ruby Way, and various online tutorials to help me with this to no avail. > > require 'Qt' > > class Form1 < Qt::Widget > slots > attr_reader :textLabel1 > attr_reader :textLabel2 > attr_reader :textLabel3 > attr_reader :pushButton1 > attr_reader :lineEdit1 > attr_reader :lineEdit2 > attr_reader :lineEdit3 #I snipped the extra stuff that was irrelevant to the example. #Please learn to make minimal examples. def initialize #somewhere deep in initialize > > #start my connections > Qt::Object.connect(@lineEdit1, SIGNAL("textChanged(const QString &)"), > @lineEdit3, SLOT('update(const QString &)') ) end #I snipped the extra stuff > > #start my slot methods > def update > @lineEdit3.setText( trUtf8("fudge")) > end > #end my slot methods > Here is the error message I get when I try to run it: > > ruby -KA -C"/home/hujraad/Desktop/sum" -I"/home/hujraad/Desktop/sum/." > "sum.rb" > QObject::connect: No such slot Qt::LineEdit::update(const QString&) > QObject::connect: (sender name: 'lineEdit1') QObject::connect: > (receiver name: 'lineEdit3') *** Exited normally *** > > > I believe I have the connections in correctly, as I have already > practiced that with other connections. Have I improperly syntaxed the > update() method? When you call connect as you did with the signature (CONTROL, SIGNAL, CONTROL, SLOT), then the slot is called on the second control, as though you had called @lineEdit3.update("foobar") You're trying to call Form1#update, and the simplest way to do that is use a block as the code to call. connect accepts a block like so: @lineEdit1.connect(SIGNAL("textChanged(const QString &)")) do |thestr| lineEdit3.setText( trUtf8("fudge")) end Once you know how to do that, you can use method(:update) to get a handle to the update method on the current object, then using the unary & operator to treat it like a block, as follows: @lineEdit1.connect(SIGNAL("textChanged(const QString &)"), &method(:update)) -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/