Results 1 to 2 of 2

Thread: QtScript

  1. #1
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question QtScript

    Hi guys...

    Currently i am learning QtScripts...and while trying out code snippets from Assistant.
    I got a few errors....It is a programmatically incorrect. Could some body help me out with this code.

    I am sending it as an attachment (Main.cpp).

    In assistant section "Making C++ Class Member Functions Available in QtScript", QtScript overview

    Consider this part

    QScriptEngine eng;
    eng.globalObject().setProperty("obj", eng.newQObject(myObj)); -------------(A)

    qDebug() << eng.evaluate(
    "var obj = new MyObject;\n" -------------(B)
    - - -
    "print('Enabled: ' + obj.enabled);\n"
    "print('isEnabled: ' + obj.isEnabled());" -------------(C)
    );

    (A) As usual, MyObject needs to be available to the engine 'eng'.
    (B) Gives an error stating that MyObject is not defined. I even tried removing this statement, since there is no use of redeclaring global property name 'obj' already declared in (A).
    (C) Gives an error isEnabled() is not defined.
    (D) Why is the inclusion of Q_OBJECT macro giving meta object errors? The attached code does not have one and is even executing.

    How could i improvise on this??
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2008
    Location
    Bangalore, India
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Smile Re: QtScript

    this one now works....

    Qt Code:
    1. //CLASS DECL
    2. //USE THE Q_OBJECT macro
    3.  
    4. #include "main.moc"
    5.  
    6. int main(int argc, char **argv)
    7. {
    8. Q_UNUSED(argc)
    9. Q_UNUSED(argv)
    10.  
    11. MyObject *myObj = new MyObject;
    12.  
    13. QScriptEngine eng;
    14. eng.globalObject().setProperty("obj", eng.newQObject(myObj));
    15.  
    16. qDebug() << eng.evaluate(
    17. [INDENT][INDENT]"obj.enabled = true;\n"
    18. "print('Enabled: ' + obj.enabled);\n"
    19. "print('isEnabled: ' + obj.isEnabled());"
    20. ).toString();[/INDENT][/INDENT]
    21. return 0;
    22. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QtScript basic tutorial
    By thomir in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2013, 04:17
  2. Is webkit functionality a superset of qtscript?
    By jurojon in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2008, 23:12
  3. Using enums in QtScript
    By Orphelic in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 11:55
  4. QtScript Q_ENUM problem
    By oc2k1 in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2007, 16:07

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.