Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Strict knowledge of subset of properties involved in a userdefined script
laurent bauer last edited by
I've a QScriptvalue m_ParametersObject containing a set of properties/double P1,P2...Pn
I want the user to define formula in a QTextEdit where a formula is a relation between a choice of parameters
ex: Let the parametersObject contain p1..p5.
The user defines the followinf formula in a textEdit : "p5 = p2+p4"
I need to know that p2 and p4 are involved in the forumla and that p1 and p3 are not involved.
void AddFormulaDialog::formulaChanged() // textEdit slot
QString formula = ui->textEdit->toPlainText();
QScriptEngine * engine = m_ParametersObject->engine();
// m_ParametersObject is a QScriptValue, with parameters as properties p1, p2...pn
QScriptContext * context = engine->pushContext();
QScriptValue res = engine->evaluate(formula);
QPushButton * okButton = ui->buttonBox->button(QDialogButtonBox::Ok); okButton->setEnabled(!res.isError()); engine->popContext();
With this, I can get the analytical formula and the evaluation, but not the topological information: I don't know which parameters are actually involved int the relation.
QScriptValueIterator doesn't help here:
QScriptValueIterator it(*m_ParametersObject) gives me all properties of the context (not only of the formula)
QScriptValueIterator it(res) gives nothing.
Is there a way (even completely different), to strictly retrieve the set of properties involved in the interactively user defined formula?
Note: I'm new to QtScript
Thank you in advance