Results 1 to 10 of 10

Thread: QScriptValue with simple typedef types

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QScriptValue with simple typedef types

    Hi there!

    I can't get a simple typedefed type (like typedef CDB_ID quint32;) to work correctly as a QScriptValue / QVariant.

    When I try to call a member function returning a CDB_ID from a qtscript, it always returns zero. Can anybody point me in the right direction?

    Qt Code:
    1. typedef int CDB_ID;
    2.  
    3. Q_DECLARE_METATYPE(CDB_ID)
    4.  
    5. class SClass : public QObject
    6. { Q_OBJECT
    7. public slots:
    8. int TestA() {return 5;}
    9. CDB_ID TestB() {return 8;}
    10. };
    11.  
    12. QScriptValue CDB_IDToScriptValue(QScriptEngine *engine,const CDB_ID &in)
    13. {
    14. return engine->newVariant(QVariant::fromValue(in));
    15. }
    16.  
    17. void CDB_IDFromScriptValue(const QScriptValue &object, CDB_ID &out)
    18. {
    19. out = object.toVariant().value<CDB_ID>();
    20. }
    21.  
    22. ..
    23.  
    24. QScriptEngine eng;
    25. qRegisterMetaType<CDB_ID>("CDB_ID");
    26. qScriptRegisterMetaType<CDB_ID>(&eng, CDB_IDToScriptValue, CDB_IDFromScriptValue);
    27.  
    28. SClass* s = new SClass();
    29. QScriptValue obj = eng.newQObject(s);
    30.  
    31. // Return value as CDB_ID .. always returns 0!
    32. fun = eng.evaluate("function() {return this.TestB();}");
    33. res = fun.call(obj,QScriptValueList());
    34. CDB_ID cdbid = 4;
    35. CDB_IDFromScriptValue(res,cdbid);
    36. qDebug() << "B: " << res.toString() << res.isVariant() << cdbid << " error: " << eng.uncaughtException().toString();
    To copy to clipboard, switch view to plain text mode 

    Attached you will find a working demo of my problem!

    Thx a lot!

    Johannes
    Attached Files Attached Files

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
  •  
Qt is a trademark of The Qt Company.