QScriptEngine engine; QScriptValue strValue = engine.evaluate("\"Hello, World!\""); //evaluating a string value if(strValue.isString()){ qDebug() << "The value is a string: " << strValue.toString(); } else { qDebug() << "The value is not a string."; }
QScriptEngine engine; QScriptValue numValue = engine.evaluate("123"); //evaluating a number value if(numValue.isString()){ qDebug() << "The value is a string: " << numValue.toString(); } else { qDebug() << "The value is not a string. It is a number: " << numValue.toNumber(); }In this example, we create a QScriptEngine and use it to evaluate a JavaScript number value. We then check if the value is a string using the isString() function. Since it is not a string, we print out the number value instead using the toNumber() function. Package/library: Qt Core library.