Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: proving aruments to scripting..

  1. #1
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default proving aruments to scripting..

    hi,

    following is my code
    Qt Code:
    1. QScriptEngine engine;
    2. QScriptValue ctor,scriptUi,calc,scriptUi2;
    3.  
    4. QString scriptFileName("./AnotherJs.js");
    5. QFile scriptFile(scriptFileName);
    6. scriptFile.open(QIODevice::ReadOnly);
    7. engine.evaluate(scriptFile.readAll(), scriptFileName);
    8. bool b1 = engine.hasUncaughtException();
    9. scriptFile.close();
    10.  
    11. ctor = engine.evaluate("on_m_TcpSend_clicked");
    12. b1 = engine.hasUncaughtException();
    13. scriptUi = engine.newQObject(this, QScriptEngine::ScriptOwnership);
    14. b1 = engine.hasUncaughtException();
    15. calc = ctor.construct(QScriptValueList() << scriptUi);
    16. b1 = engine.hasUncaughtException();
    To copy to clipboard, switch view to plain text mode 
    here in line 11: i m creating new object giving "this" as parameter, and in line 13: i am proving the scriptui as a parameter to the ctor's constructor.
    my question is if i can provide more that 1 arguments to scripting. (ex:- if i want to give this and some other object both as a parameter??)
    Please answer...
    Last edited by prachi kamble; 23rd April 2015 at 09:46.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: proving aruments to scripting..

    Quote Originally Posted by prachi kamble View Post
    my question is if i can provide more that 1 arguments to scripting
    Hint 1: the argument of construct() is called "args".
    Hint 2: it is a list.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    yes, i know that, that's y i tried to provide the list of arguments, but i don't know exact syntax for it . searching for the syntax...
    i tried something like this

    calc = ctor.construct(QScriptValueList() << scriptUi << scriptui2);

    is there any mistake in the code??

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: proving aruments to scripting..

    That looks ok.

    Cheers,
    _

  5. #5
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    ok... but its not giving me the expected result...
    ok i try more on it...

  6. #6
    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: proving aruments to scripting..

    What exactly are you expecting to obtain with this code? You realize you are calling a constructor of a function? This will not call the function (provided that on_m_TcpSend_clicked does evaluate to a function).
    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.


  7. #7
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    yes, it is constructing the given function.the code above works well, it is evaluating the function and working well, it also calls the function and executes the code in it,(when i provide only one parameter). but there is a requirement to provide 2 parameters.

  8. #8
    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: proving aruments to scripting..

    How do you evaluate those two parameters in the function?
    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.


  9. #9
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    above written is the code in qt

    following is the code in java script

    function on_m_TcpSend_clicked(param1,param2)
    {
    this.ui = param1;
    param1.SomeControl.text = "ABC"; //this line gets executed if only param1 is given as parameter
    SendData(param2); //this function is written in another js file.
    }

  10. #10
    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: proving aruments to scripting..

    Have you tried checking the "arguments" object passed to the function?

    javascript Code:
    1. function on_m_TcpSend_clicked()
    2. {
    3. this.ui = arguments[0];
    4. param1.SomeControl.text = "ABC"; //this line gets executed if only param1 is given as parameter
    5. SendData(arguments[1]); //this function is written in another js file.
    6. }
    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.


  11. #11
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    i tried spmeting like below

    code in QT:-
    ctor = engine.evaluate("on_m_TcpSend_clicked");
    b1 = engine.hasUncaughtException();
    scriptUi = engine.newQObject(this, QScriptEngine::ScriptOwnership);
    b1 = engine.hasUncaughtException();

    scriptUi2 = engine.newQObject(objtcpwrapper, QScriptEngine::ScriptOwnership);
    b1 = engine.hasUncaughtException();
    QScriptValueList objlist;
    objlist.append(scriptUi);
    objlist.append(scriptUi2);
    calc = ctor.construct(objlist);
    b1 = engine.hasUncaughtException();

    code in Java:-

    function on_m_TcpSend_clicked(param)
    {
    this.ui = param[0];
    SendData(param[1]);
    }

    but it is not working...

    I have one more question.. can i declare a global or file lavel variable in the java script file?? if it is possible.. it will solve my issue

  12. #12
    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: proving aruments to scripting..

    Did you try the arguments object as I told you?
    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.


  13. #13
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    Yes sir ,I tried... Not working in java script...

  14. #14
    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: proving aruments to scripting..

    Quote Originally Posted by prachi kamble View Post
    Yes sir ,I tried... Not working in java script...
    Then you tried it wrong because it is part of JavaScript specification.

    https://developer.mozilla.org/en-US/...ions/arguments
    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.


  15. #15
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    i got to know.. what u r saying is java script with HTMl, and java script with Qt has some different methods. as i have tried many thing which are perfectly working in java with htmal(ex- confirm method for msgbox, require method for TCP connection), but it gives me error while used in qt scripting. so argument method might not be working in qt .

  16. #16
    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: proving aruments to scripting..

    This works just fine:

    Qt Code:
    1. #include <QScriptEngine>
    2. #include <QCoreApplication>
    3.  
    4. int main(int argc, char **argv) {
    5. QCoreApplication app(argc, argv);
    6. QScriptEngine engine;
    7. engine.evaluate("function func() { for(var i = 0; i < arguments.length; ++i) print('Arg ', i+1, ': ', arguments[i]); } func('a1', 'a2');");
    8. return 0;
    9. }
    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.


  17. #17
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    ok... that's good...
    but what if i just want to give just function name and don't want to write function body while evaluating it.then??
    i mean to say.. i have a js file.. in that function body is already written with 2 parameters . and want to call it from qt script and want to give parameters list there.. pls help if u know

  18. #18
    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: proving aruments to scripting..

    Quote Originally Posted by prachi kamble View Post
    but what if i just want to give just function name and don't want to write function body while evaluating it.then??
    i mean to say.. i have a js file.. in that function body is already written with 2 parameters . and want to call it from qt script and want to give parameters list there.. pls help if u know
    The code doesn't care where the function is defined.
    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.


  19. #19
    Join Date
    Apr 2015
    Posts
    26
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Windows

    Default Re: proving aruments to scripting..

    engine.evaluate("function func() { for(var i = 0; i < arguments.length; ++i) print('Arg ', i+1, ': ', arguments[i]); } func('a1', 'a2');");

    ok..wherever the function is defines.. do i need to provide function body while evaluating then...or i can simply write

    engine.evaluate("function func('a1', 'a2');");

  20. #20
    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: proving aruments to scripting..

    Quote Originally Posted by prachi kamble View Post
    or i can simply write

    engine.evaluate("function func('a1', 'a2');");
    You definitely can't write that because this code has a syntax error.

    As I said the code works regardless where the function is defined.

    Qt Code:
    1. #include <QScriptEngine>
    2. #include <QCoreApplication>
    3.  
    4. int main(int argc, char **argv) {
    5. QCoreApplication app(argc, argv);
    6. QScriptEngine engine;
    7. engine.evaluate("function func() { for(var i = 0; i < arguments.length; ++i) print('Arg ',i+1,': ', arguments[i]); }"); // define here
    8. engine.evaluate("func('a1', 'a2');"); // call here
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

    This also works (notice the parenthesis in function definition):

    Qt Code:
    1. #include <QScriptEngine>
    2. #include <QCoreApplication>
    3.  
    4. int main(int argc, char **argv) {
    5. QCoreApplication app(argc, argv);
    6. QScriptEngine engine;
    7. QScriptValue fun = engine.evaluate("(function func() { for(var i = 0; i < arguments.length; ++i) print('Arg ',i+1,': ', arguments[i]); })");
    8. fun.call(QScriptValue(), QScriptValueList() << "a1" << "a2");
    9. return 0;
    10. }
    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.


Similar Threads

  1. Scripting in Qt
    By Kamalpreet in forum Newbie
    Replies: 3
    Last Post: 13th November 2014, 15:23
  2. Qt Scripting Potentialities (ProcessingJS+QT)
    By gabon in forum Qt Programming
    Replies: 4
    Last Post: 17th May 2010, 09:44
  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.