Results 1 to 3 of 3

Thread: QtScript QPoint

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QtScript QPoint

    Hi trolls,

    I'm trying to make a QPoint newable and modifyable from QtScript.

    I've defined the "QPoint ctor" and "QPoint::setX" function in my script.
    The QPoint constructs properly, but I can't seem to find the proper
    implementation for setX(int x);

    Qt Code:
    1. inline QScriptValue QPoint_setX(QScriptContext *ctx, QScriptEngine *eng)
    2. {
    3. QPoint object = ctx->thisObject().toVariant().toPoint();
    4.  
    5. if (ctx->argumentCount() == 1 && ctx->argument(0).isNumber())
    6. {
    7. object.setX(ctx->argument(0).toInt32());
    8.  
    9. // This doesn't seem to apply changes
    10. ctx->setThisObject(eng->newVariant(object));
    11. }
    12. return eng->undefinedValue();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Is it possible to do such a thing ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtScript QPoint

    You should return the new value.

    Qt Code:
    1. inline QScriptValue QPoint_setX(QScriptContext *ctx, QScriptEngine *eng)
    2. {
    3. QPoint object = ctx->thisObject().toVariant().toPoint();
    4.  
    5. if (ctx->argumentCount() == 1 && ctx->argument(0).isNumber())
    6. {
    7. object.setX(ctx->argument(0).toInt32());
    8. return eng->newVariant(object);
    9. }
    10. return eng->undefinedValue();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    bunjee (19th May 2009)

  4. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QtScript QPoint


Similar Threads

  1. QtScript Binding problem with QWidget
    By zack in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 09:38
  2. QtScript Q_ENUM problem
    By oc2k1 in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2007, 16:07
  3. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  4. Confusion with QPoint
    By therealjag in forum Qt Programming
    Replies: 9
    Last Post: 14th February 2006, 17:31

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.