I found the solution !!
Thank you for the hint given to me :-)
The solution is to use QDeclarativeExpression instead of QMetaObject::invokeMethod.
Here are the details:
suppose you have the following QML component
Experiment {
function initGeneration( id ) {
// some javascript code here
}
Then you can call the function from C++ using the invokeMethod:
QMetaObject::invokeMethod( qe_experiment, "initGeneration", Qt::DirectConnection, Q_ARG(QVariant, generation) );
But in this way, if there is a javascript error or exception evaluating the function there will be no way to report a message to the user.
Instead, it is possible to call the function using a QDeclerativeExpression in this way:
qe_expr->setExpressio( QString("initGeneration(%1);").arg(generation) );
qe_expr->evaluate();
if ( qe_expr->hasError() ) {
qDebug() << qe_expr->error();
qe_expr->clearError();
}
And in this way, it will be prompted an error message specifying the error and the line number.
Thank you very much,
Gianluca.
↧