Custom QTreeWidgetItem class in QtScript



  • Hi,
    I am trying to make custom qtreewidgetitem class in QtScript. I doing it as:

    ================ main.h
    @public CustomTreeWidgetItemClass : QTreeWidgetItem
    {
    public:
    CustomTreeWidgetItemClass();
    ~CustomTreeWidgetItemClass();
    void setValue(QString value);
    QString getValue();
    };
    Q_DECLARE_METATYPE(CustomTreeWidgetItemClass*)
    @
    =============== main.cpp
    @static QScriptValue construct (QScriptContext *context, QScriptEngine *engine)
    {
    CustomTreeWidgetItemClass *object = new CustomTreeWidgetItemClass();
    return engine->newScriptValue(object);
    }

    int main()
    {
    engine.globalObject().setPropert("CustomTreeWidgetItemClass", engine.newFunction(construct));
    }
    @
    ============================ main.js
    @var treeItem = new CustomTreeWidgetItemClass();
    treeItem.setText("123"); // it does not execute when making instance as
    // CustomTreeWidgetItemClass *object = new CustomTreeWidgetItemClass();
    // BUT it does execute when i cast to QTreeWidgetItem as
    // QTreeWidgetItemClass *object = new CustomTreeWidgetItemClass();
    @
    Can anyone please guide me how can achieve custom class declaration in qtscript. I am new to qt/script so please guide me accordingly.

    Thank you in advance.

    [Edit: Added @ tags around code -- mlong]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.