Ok so as I understand it you are simply asking how to create a signal with two parameters and how to trigger it when the value of one of the input boxes change?
in your class definition you define signals like this
{
Q_OBJECT
signals:
void multiply(const QString& a, const QString& b);
private slots:
void onVariableChanged();
void doMultiplication(const QString& a, const QString& b);
...
};
class myObject : public QWidget
{
Q_OBJECT
signals:
void multiply(const QString& a, const QString& b);
private slots:
void onVariableChanged();
void doMultiplication(const QString& a, const QString& b);
...
};
To copy to clipboard, switch view to plain text mode
then connect the signals and slots
connect(numberA, SIGNAL(textChanged(const QString&)), this, SLOT(onVariableChanged()));
connect(numberB, SIGNAL(textChanged(const QString&)), this, SLOT(onVariableChanged()));
connect(this, SIGNAL(multiply(const QString&, const QString&), this, SLOT(doMultiplication(const QString&, const QString&));
connect(numberA, SIGNAL(textChanged(const QString&)), this, SLOT(onVariableChanged()));
connect(numberB, SIGNAL(textChanged(const QString&)), this, SLOT(onVariableChanged()));
connect(this, SIGNAL(multiply(const QString&, const QString&), this, SLOT(doMultiplication(const QString&, const QString&));
To copy to clipboard, switch view to plain text mode
We use the text changed signal to trigger the creation of our more "complicated" multiplication signal and then emit it
void MyObject::onVariableChanged()
{
//Query any data we want here and send a new signal
emit multiply(numberA->text(), numberB->text());
}
void MyObject::doMultiplication(const QString& a, const QString& b)
{
double x = a.toDouble() * b.toDouble();
result
->setText
(QString::number(x
));
}
void MyObject::onVariableChanged()
{
//Query any data we want here and send a new signal
emit multiply(numberA->text(), numberB->text());
}
void MyObject::doMultiplication(const QString& a, const QString& b)
{
double x = a.toDouble() * b.toDouble();
result->setText(QString::number(x));
}
To copy to clipboard, switch view to plain text mode
Bookmarks