Reading examples and documentation I start to believe that making a custom SIGNAL is not a difficult task. Trying to do it though I realize that I cannot do it!!
Here's a simple example, that if I understand it I will be able to make more custom signals.
- a line edit for number A
- a line edit for number B
- a line edit to present the result of the Multiplication
Here is the corresponding code:
MyDialog
::MyDialog(QWidget *parent
){
numberA->setText("1.0");
numberB->setText("1.0");
result->setText("1.0");
vboxlayout->addWidget(numberA);
vboxlayout
->addWidget
(new QLabel("x"));
vboxlayout->addWidget(numberB);
vboxlayout
->addWidget
(new QLabel("="));
vboxlayout->addWidget(result);
setLayout(vboxlayout);
}
{
double A,B,Res;
A= Astring.toDouble();
B= Bstring.toDouble();
Res = A*B;
ResString.setNum(Res);
result->setText(ResString);
}
MyDialog::MyDialog(QWidget *parent)
: QWidget(parent)
{
QLineEdit *numberA = new QLineEdit;
QLineEdit *numberB = new QLineEdit;
result = new QLineEdit;
numberA->setText("1.0");
numberB->setText("1.0");
result->setText("1.0");
vboxlayout = new QVBoxLayout(this);
vboxlayout->addWidget(numberA);
vboxlayout->addWidget(new QLabel("x"));
vboxlayout->addWidget(numberB);
vboxlayout->addWidget(new QLabel("="));
vboxlayout->addWidget(result);
setLayout(vboxlayout);
}
void MyDialog::showMultiplication(QString Astring,QString Bstring)
{
double A,B,Res;
QString ResString;
A= Astring.toDouble();
B= Bstring.toDouble();
Res = A*B;
ResString.setNum(Res);
result->setText(ResString);
}
To copy to clipboard, switch view to plain text mode
QUESTION:
When the user inserts a new number (anywhere A or B) the multiplication result should be shown directly in the result line edit. The SLOT is obliously the showMultiplication(QString Astring,QString Bstring).
The SIGNAL should be something like
sendNewNumbersForMultiplication(QString ,QString )
BUT, I really cannot understand how to implement it!!
Any help?
Bookmarks