Results 1 to 2 of 2

Thread: Qt types exposed as Variant in javascript

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Qt types exposed as Variant in javascript

    Hello,

    In exposing my C++ objects to javascript, I have properties of types QSizeF, QColor and other Qt types:
    Qt Code:
    1. class Control : public QGraphicsWidget{
    2. Q_OBJECT
    3. Q_PROPERTY (QSizeF size READ getSize WRITE setSize )
    4. Q_PROPERTY (QColor bgColor READ getBgColor WRITE setBgColor)
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    These properties are converted to Variant in javascript, so this code won't work :
    Qt Code:
    1. myControl = new Control();
    2. myControl.size.height = 40;
    To copy to clipboard, switch view to plain text mode 

    What do I have to do to access these properties in javascript? Do I have to set a default prototype for QSizeF and others, or do I have to create my own Size,Color, classes?

    Thank you,

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: Qt types exposed as Variant in javascript

    answering my own question in case a fellow newbie encounters the same....

    Qt Code:
    1. QScriptValue toScriptValueQPointF(QScriptEngine *engine, const QPointF &s) {
    2. QScriptValue obj = engine->newObject();
    3. obj.setProperty("x", QScriptValue(engine, s.x()));
    4. obj.setProperty("y", QScriptValue(engine, s.y()));
    5. return obj;
    6. }
    7.  
    8. void fromScriptValueQPointF(const QScriptValue &obj, QPointF &s) {
    9. s.setX(qreal(obj.property("x").toNumber()));
    10. s.setY(qreal(obj.property("y").toNumber()));
    11. }
    12.  
    13. int main() {
    14. ...
    15. QScriptEngine engine;
    16. qScriptRegisterMetaType(&engine, toScriptValueQPointF, fromScriptValueQPointF);
    17. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 10th December 2009, 16:37
  2. VARIANT <-> QVariant
    By will49 in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2009, 23:39
  3. can't show value of variant
    By guchangyuan in forum Qt Tools
    Replies: 3
    Last Post: 3rd August 2009, 12:34
  4. accumulate variant
    By mickey in forum General Programming
    Replies: 6
    Last Post: 24th August 2008, 11:56
  5. pixmap from variant
    By kernel_panic in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2007, 10:40

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.