Quote Originally Posted by eleanor View Post
How can I accept the number from QLineEdit and then multiply it by 4 and then output it with QLabel?
To restrict the user to input only numbers, you can use a QIntValidator:
Qt Code:
  1. QValidator *validator = new QIntValidator(100, 999, this);
  2. QLineEdit *edit = new QLineEdit(this);
  3. // the edit lineedit will only accept integers between 100 and 999
  4. edit->setValidator(validator);
To copy to clipboard, switch view to plain text mode 
or you can use input mask:
Qt Code:
  1. QLineEdit *edit = new QLineEdit(this);
  2. // the edit lineedit will only accept 0-3 digit chars
  3. edit->setInputMask("000");
To copy to clipboard, switch view to plain text mode 

For multiplying, you need a custom slot:
Qt Code:
  1. // class declaration
  2. class mojClass : public ...
  3. {
  4. ...
  5. private slots:
  6. void customSlot(const QString& input);
  7. ...
  8. };
  9.  
  10. // class implementation
  11. mojClass::mojClass()
  12. {
  13. ...
  14. connect(lineedit1,SIGNAL(textChanged(const QString&)),this,SLO T(customSlot(const QString&)));
  15. }
  16.  
  17. // the custom slot
  18. void mojClass::customSlot(const QString& input)
  19. {
  20. int num = 4 * input.toInt();
  21. label3->setNum(num);
  22. }
To copy to clipboard, switch view to plain text mode