Example Code for using x-qt-plugin with JavaScript and HTML Elements.
<script type="text/javascript"> /* <![CDATA[ */ function checkForm() { var json = document.xRegistrationFormular.data; document.getElementById( "code" ).innerHTML = decodeURI(json); return false; } function setData() { document.xRegistrationFormular.data = "{\"encoding\":\"UTF-8\",\"length\":10, \"person_age\":21,\"person_house\":true, \"person_house_female\":false, \"person_house_male\":true, \"person_name\":\"Hans\",\"person_nickname\":\"Tester\",\"person_password\":\"007\",\"person_surname\":\"Musterman\",\"use_space\":false}"; } /* ]]> */ </script> <form action="#" method="post" target="_self" onsubmit="return checkForm();"> <div> <object type="application/x-qt-plugin" width="600" height="250" id="register_widget" classid="XRegistrationFormular" name="xRegistrationFormular"> <param name="title" value="Registration" valuetype="data" /> </object> </div> <div style="text-align:center;"> <input type="reset" onClick="document.xRegistrationFormular.restore();" /> <input type="button" onClick="setData();" value="Insert" /> <input type="submit" /> </div> </form> <pre id="code">Json</pre>
#ifndef XREGISTRATIONFORMULAR_H #define XREGISTRATIONFORMULAR_H /* QtCore */ #include <QtCore/QObject> #include <QtCore/QString> #include <QtCore/QVariant> /* QtGui */ #include <QtGui/QWidget> /* QtScript */ #include <QtScript/QScriptable> /* Ui */ #include "ui_xregistrationformcomponent.h" class Q_DECL_EXPORT XRegistrationFormular : public QWidget , protected Ui::XRegistrationFormComponent , protected QScriptable { Q_OBJECT Q_CLASSINFO ( "Author", "Jürgen Heinemann (Undefined)" ) Q_CLASSINFO ( "URL", "http://www.hjcms.de" ) Q_PROPERTY ( QString title READ title WRITE setTitle ) Q_PROPERTY ( QString data READ data WRITE setData ) private: /** Initial default Map Properties e.g. encoding,use_space... */ inline const QVariantMap initMap() const; /** Modify GroupBox title */ void setElementData ( const QString &name, const QVariant &value ); public Q_SLOTS: /** * Reset Form */ void restore(); public: explicit XRegistrationFormular ( QWidget * parent = 0 ); /** * Modify GroupBox title */ void setTitle ( const QString &t ); /** * Read current GroupBox title */ QString title() const; /** * Set Input Values with Json String, for construction about * this String see @ref data */ void setData ( const QString &d ); /** * create a list with all scriptable objects and here values. * This method will build a json string. * @code * { * "encoding" : "UTF-8", * "length" : Array size, * "use_space" : Boolean, * "::objectName()" : mixed Values, ... * } * @endcode * for more information read: @ref http://qjson.sourceforge.net/usage.html */ QString data() const; virtual ~XRegistrationFormular(); }; #endif