Results 1 to 1 of 1

Thread: QScript + SimpleClass not working

  1. #1
    Join Date
    Oct 2009
    Posts
    6
    Thanked 2 Times in 2 Posts

    Default QScript + SimpleClass not working

    Hi all,
    i have simple class which is used in QScript

    Qt Code:
    1. //-------------------------------- myobject.h----------------------------
    2. class MyObject : public QObject
    3. {
    4. Q_OBJECT
    5. public:
    6.  
    7. MyObject(QObject *parent = 0);
    8.  
    9. Q_SCRIPTABLE int intern;
    10. Q_INVOKABLE QString name();
    11. Q_INVOKABLE int add(int b=0);
    12.  
    13. Q_INVOKABLE bool operator==(const MyObject &second) const;
    14. Q_INVOKABLE MyObject operator+(int b);
    15.  
    16. ~MyObject();
    17. };
    18. //-------------------------------- myobject.cpp----------------------------
    19. MyObject::MyObject(QObject *parent)
    20. : QObject(parent)
    21. {
    22. this->intern=0;
    23. }
    24. MyObject::~MyObject()
    25. {
    26. };
    27. QString MyObject::name()
    28. { return QString("MyObject");
    29. };
    30. int MyObject::add(int b)
    31. { this->intern=this->intern+b;
    32. return this->intern;
    33. };
    34.  
    35. bool MyObject::operator==(const MyObject &second) const
    36. { return this->intern==second.intern;
    37. };
    38. MyObject MyObject::operator+(int b)
    39. { this->intern=this->intern+b;
    40. return this;
    41. } ;
    To copy to clipboard, switch view to plain text mode 
    and executing code
    Qt Code:
    1. Q_SCRIPT_DECLARE_QMETAOBJECT(MyObject, QObject*);
    2. ...
    3. QScriptEngine eng;
    4.  
    5.  
    6. QScriptValue fClass = eng.scriptValueFromQMetaObject<MyObject>();
    7. eng.globalObject().setProperty("MyObject", fClass);
    8.  
    9. qDebug()<<"var a=new MyObject()"<<eng.evaluate("var a=new MyObject()").toString();
    10. qDebug()<<"a.name()"<<eng.evaluate("a.name()").toString();
    11. qDebug()<<"a.intern=3"<<eng.evaluate("a.intern=3").toString();
    12. qDebug()<<"a.intern"<<eng.evaluate("a.intern").toString();
    13. qDebug()<<"a.add(5)"<<eng.evaluate("a.add(5)").toString();
    14. qDebug()<<"a.intern"<<eng.evaluate("a.intern").toString();
    To copy to clipboard, switch view to plain text mode 
    In my opinion should be variable a represents class MyCObject and a.intern should be 3+5
    it is not
    is it right or bug? please send any idea you have

    thanks
    TDT

    PS: is it possible override operator+ inside qscript?
    ----------------------------------------------------------
    working on wxp, VS express 2008+QT4.5.0
    Last edited by tdt; 14th February 2010 at 08:31.

Similar Threads

  1. Replies: 1
    Last Post: 19th February 2010, 11:02
  2. QScript script side callbacks
    By starlon in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 23:29
  3. QScript workbench in 4.3
    By jh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2009, 13:53
  4. QScript + get function call parameters
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2009, 15:30
  5. QVariantList from QScript?
    By musla in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2009, 10:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.