Hi,

I need to create a Qt script dynamically from user input formular using QRegExp. I got completely lose. Please help.

I have a list of QVector<float> a, aa, b, etc... which I can transfer to QScriptEngine.

I have a QLineEdit to allow user to enter their own formular to compute a new one, for instance, use can enter the following string (case insensitive):

math.max(a)/math.min(aa)*b+aa/b-Math.pow(aa)/a/MATH.pow(a,2.14)

I need to convert this string into QtScript dynamically, so it should become:

Qt Code:
  1. var max_a = max( a ); // max is a global function somewher in my script library
  2. var min_aa = min( aa ); // min is a global function somewher in my script library
  3.  
  4. var result = new Array;
  5. for ( var idx = 0; idx < a.length; idx++ ) {
  6. result[ idx ] = max_a / min_aa * b[ idx ] + aa[ idx ] / b[ idx ] - Math.pow( aa[ idx ] ) / a[ idx ] / Math.pow( a[ idx ], 2.14 );
  7. }
To copy to clipboard, switch view to plain text mode 

I believe I need to use QRegExp, but am unable to get it done.

Many thanks!!