QT自带的有一个数学表达式计算类 QScriptEngine
不用自己搞什么算法。
#include <QScriptEngine>
QT += script
QScriptEngine myEngine;
QScriptValue three = myEngine.evaluate("1 + 2");
QScriptValue fun = myEngine.evaluate("(function(a, b) { return a + b; })");
QScriptValueList args; args << 1 << 2;
QScriptValue threeAgain = fun.call(QScriptValue(), args);