You can replace print() your own implementation:
First, define a C ++ function that does what you want. In this case, it is simply empty for presentation:
QScriptValue myPrint( QScriptContext * ctx, QScriptEngine * eng ) { return QScriptValue(); }
Then set this function as the new print() :
QScriptEngine e = ...; e.globalObject().setProperty( "print", e.newFunction( &myPrint ) ); e.evaluate( "print(21);" );
source share