From: Matthew Borgeson Date: 2009-08-28T06:42:58+09:00 Subject: QTRuby Strategy for setting up an addition twixt 2 lineEdits Hello- Thanks to some help previously received here (thanks to Ken Bloom), I have managed to practice using blocks of code with the connect method to assign values to several class variables using lineEdit objects and display them to a third lineEdit object. I am now trying to figure out a strategy for using a method to: 1. determine when two class variables have BOTH had their values changed by changes in 2 separate lineEdit fields and 2.once detected, the method will calculate the sum of these two numbers and display it in a third lineEdit field. I have tried to use the sum method alone rather than as a slot as well as signaling the sum slot method after each of the lineEdit boxes have been changed to no avail. My (relevant) code currently: require 'Qt' class Form1 < Qt::Widget slots 'sum()' attr_reader :textLabel1 attr_reader :textLabel2 attr_reader :textLabel3 attr_reader :pushButton1 attr_reader :lineEdit1 attr_reader :lineEdit2 attr_reader :lineEdit3 def initialize(parent = nil, name = nil, fl = 0) super if name.nil? setName("Form1") end @a=0 @b=0 <-----snipped widget geomeotries-----> #sets @a and @b by user input @lineEdit1.connect(SIGNAL("textChanged(const QString &)")) do |x| @a = x end @lineEdit2.connect(SIGNAL("textChanged(const QString &)")) do |x| @b = x end Qt::Object.connect(@pushButton1, SIGNAL("clicked()"), @lineEdit1, SLOT("clear()") ) Qt::Object.connect(@pushButton1, SIGNAL("clicked()"), @lineEdit2, SLOT("clear()") ) Qt::Object.connect(@pushButton1, SIGNAL("clicked()"), @lineEdit3, SLOT("clear()") ) @lineEdit1.connect(SIGNAL("textChanged(const QString &)")) do |x| if @b > 0 sum end @lineEdit2.connect(SIGNAL("textChanged(const QString &)")) do |x| if @a > 0 sum end end def sum if (@a > 0 and @b > 0) @c = @a + @b emit @lineEdit3.setText(@c.to_s) end end def languageChange() setCaption(trUtf8("Form1")) @textLabel1.setText( trUtf8("addend 1") ) @textLabel2.setText( trUtf8("addend 2") ) @textLabel3.setText( trUtf8("sum") ) @pushButton1.setText( trUtf8("Reset") ) end end I don't know if this is the right strategy...it seemed more cut and dried to me when I was writing CLI programs... Any conceptual help or code snippets would be appreciated- Thans in advance- Matthew Borgeson -- Posted via http://www.ruby-forum.com/.