it almost copy/paste from documentation:

Qt Code:
  1. QScriptEngine p_engine;
  2. ScriptMediator p_mediator;
  3. ...
  4. QScriptValue objectValue = p_engine.newQObject(&p_mediator);
  5. p_engine.globalObject().setProperty("Mediator", objectValue);
  6. QScriptValue result = p_engine.evaluate(contents, fileName);
  7. if(result.isError())
  8. {
  9. ShowMessage("Script error",result.toString());
  10. }
To copy to clipboard, switch view to plain text mode 

where ScriptMediator defined as:
Qt Code:
  1. class ScriptMediator :public QObject
  2. {
  3. Q_OBJECT
  4. public:
  5. explicit ScriptMediator(QWidget *parent = 0);
  6.  
  7. public slots:
  8. void okClicked();
  9. void cancelClicked();
  10. void print(QString string);
  11. };
  12.  
  13. void ScriptMediator::print(QString string)
  14. {
  15. ShowMessage("Message from script",string);
  16. }
To copy to clipboard, switch view to plain text mode 

ShowMessage it is just my replacement for QMessageBox:
Qt Code:
  1. bool Config::ShowMessage(QString title, QString message, QWidget *parent)
  2. {
  3. bool retval = false;
  4. Message * dlg = new Message(title,message,parent);
  5. if(dlg->exec() == QDialog::Accepted) retval = true;
  6. delete dlg;
  7. return retval;
  8. }
To copy to clipboard, switch view to plain text mode 

where Message class defined as:
Qt Code:
  1. class Message : public QDialog
  2. {
  3. public:
  4. explicit Message(QString title,QString message,QWidget *parent = 0);
  5. ...
  6. }
  7.  
  8. Message::Message(QString title, QString message, QWidget *parent) :
  9. QDialog(parent),
  10. ui(new Ui::Message)
  11. {
  12. ui->setupUi(this);
  13. this->setWindowTitle(title);
  14. ui->message->setText(message);
  15. }
To copy to clipboard, switch view to plain text mode 
simple form with only QLabel on it
and JS script:
Qt Code:
  1. function validate()
  2. {
  3. return false;
  4. }
  5. function okClicked()
  6. {
  7. if(validate()) Mediator.okClicked();
  8. else Mediator.print( "Form validate error" );
  9. }
  10. Mediator.okButton.clicked.connect(okClicked);
To copy to clipboard, switch view to plain text mode 

In my code "Form validate error" written in Russian and I see it as abracadabra