Results 1 to 4 of 4

Thread: [QtScript] One getter/setter function for multiple properties

  1. #1
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default [QtScript] One getter/setter function for multiple properties

    What I am looking for is something like this:
    Qt Code:
    1. QScriptValue getter(QScriptContext* context, QScriptEngine* engine)
    2. {
    3. QString property = context->getProperty(); // this is what I am looking for
    4. if(property == "id")
    5. return id;
    6. else if(property == "name")
    7. return name;
    8. else if
    9. context->throwError("There is no property like that!");
    10. }
    To copy to clipboard, switch view to plain text mode 
    And so you could just do this:
    Qt Code:
    1. object.setProperty("id", engine.newFunction(getter), QScriptValue::PropertyGetter);
    2. object.setProperty("name", engine.newFunction(getter), QScriptValue::PropertyGetter);
    To copy to clipboard, switch view to plain text mode 
    So that you only have to make one getter for two properties.

    I hope you understand what I mean!
    Gillis
    Last edited by supergillis; 21st May 2009 at 12:37.

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

    Default Re: [QtScript] One getter/setter function for multiple properties

    You should be able to do that using QScriptContext::callee().
    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. #3
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QtScript] One getter/setter function for multiple properties

    Quote Originally Posted by wysota View Post
    You should be able to do that using QScriptContext::callee().
    And how should I do that then?
    Use callee() to obtain the QScriptValue that represents the function being called. This can for example be used to call the function recursively.
    So when I call callee() I get the function being called, but how do I get it's name (which should equal the property)?

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

    Default Re: [QtScript] One getter/setter function for multiple properties

    First of all you can probably store some data of yours there using QScriptValue::setData() while registering the function. If you want to know the function name directly, you'll have to dig into the internals of QScriptValue yourself. Qt sources may be very helpful here.
    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.


Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.