Results 1 to 2 of 2

Thread: QT Scripting - Native Functions

  1. #1
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QT Scripting - Native Functions

    I am trying to follow the help example. So I created a method in the class which is handling the script engine:

    Qt Code:
    1. // .h
    2. QScriptValue random(QScriptContext *context, QScriptEngine *engine);
    To copy to clipboard, switch view to plain text mode 

    Then I implemented it (it's just a test):

    Qt Code:
    1. // .cpp
    2. QScriptValue MyClass::random(QScriptContext *context, QScriptEngine *engine)
    3. {
    4. QScriptValue a = context->argument(0);
    5. return a.toNumber();
    6. }
    To copy to clipboard, switch view to plain text mode 

    When I try to register it:

    Qt Code:
    1. QScriptValue fun = engine.newFunction(random);
    2. engine.globalObject().setProperty("random", fun);
    To copy to clipboard, switch view to plain text mode 

    I get: /.../../helloscript/myclass.cpp:14: error: no matching function for call to 'QScriptEngine::newFunction(<unresolved overloaded function type>)'

    Any idea what's wrong? The only difference I can see from the example is that in my case the function is a class method.

    Is it because "global functions" have to be static?


    Thanks, chr
    Last edited by gabon; 17th May 2010 at 07:07.

  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: QT Scripting - Native Functions

    Your "random" is not a function but a class member method. Make it a standalone function or make it static.
    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. Qt Scripting Potentialities (ProcessingJS+QT)
    By gabon in forum Qt Programming
    Replies: 4
    Last Post: 17th May 2010, 09:44
  2. S60, garden and play sound with native functions
    By Lykurg in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th May 2009, 19:52
  3. Scripting question
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2008, 14:54
  4. Scripting engine
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2006, 11:36
  5. Scripting questions
    By fullmetalcoder in forum General Discussion
    Replies: 1
    Last Post: 22nd May 2006, 13:02

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.