Results 1 to 20 of 21

Thread: Why isn't it working? About external JS

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Why isn't it working? About external JS

    Hi,

    I have 3 file, 2 QML and 1 JS.

    JS:

    Qt Code:
    1. .pragma library
    2.  
    3. var totaltxt = 0;
    4. function totFunc(){
    5. totaltxt = totaltxt + 1;
    6. }
    To copy to clipboard, switch view to plain text mode 

    and first QML file includes text: Logic.totaltxt and so, it shows "0" as what we expect. However, although other QML file includes Logic.totFunc(); , it doesn't work. I mean, when second qml works, I expect new value must be 1 instead of zero.

    I did all imports to do files.

    Any idea?

  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: Why isn't it working? About external JS

    New value of what? Can you provide a minimal example reproducing the problem?
    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
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why isn't it working? About external JS

    Quote Originally Posted by wysota View Post
    New value of what? Can you provide a minimal example reproducing the problem?
    I mean new text of text: Logic.totaltxt,I think when Logic.totFunc() works, totaltxt should be totaltxt = 1, then text = 1, and so we will see 1 instead of 0 on the screen.

  4. #4
    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: Why isn't it working? About external JS

    No, I don't think it works that way.
    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.


  5. #5
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why isn't it working? About external JS

    Quote Originally Posted by wysota View Post
    No, I don't think it works that way.
    what can you suggest me? I found out that because same .js is used for 2 different qml files, it doesn't work properly. Because in QT, it protect to same variables.

    But, how can I do that? Because, one of qml files plays animation to make score, and second one shows the score. Can you imagine something?

    ----------

    edit: I also found another same question on Internet, you may check it:

    http://goo.gl/7dm7d
    Last edited by Yonetici; 23rd July 2012 at 13:19.

  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: Why isn't it working? About external JS

    I don't know what you are trying to do so it is hard to suggest a solution. How does your animation look like?
    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
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why isn't it working? About external JS

    on my Animation1.qml: (import "total.js" as Logic)

    Qt Code:
    1. ...
    2. onExited: {
    3. if(sRect.visible == true){
    4. jet1.opacity = 0;
    5. rectJet.opacity = 0;
    6. jet1_1.visible = true;
    7. jet1_2.visible = true;
    8. jet1_sound.play();
    9. if(jet1.opacity == 0){
    10. Logic.mV = 5; // here is working but it can't change text of main.qml
    11. }
    12. }
    13. }
    14. ...
    To copy to clipboard, switch view to plain text mode 

    main.qml: (import "total.js" as Logic)

    Qt Code:
    1. ...
    2. Text {
    3. id: total_txt
    4. text: Logic.totaltxt // here is working but it can't understand if or not Animation.qml changes the value
    5. anchors.topMargin: 2
    6. anchors.leftMargin: 15
    7. font.pixelSize: 50
    8. color: "white"
    9. }
    10.  
    11. Animation1 {
    12. id: animation1
    13. anchors.bottom: parent.bottom
    14. anchors.left: parent.left
    15. anchors.bottomMargin: 10
    16. anchors.leftMargin: Math.floor(Math.random()*600+20)
    17. }
    18. ...
    To copy to clipboard, switch view to plain text mode 

    total.js :

    Qt Code:
    1. .pragma library
    2.  
    3. for(var i = 0; i<1; i++){
    4.  
    5. var totaltxt = 0;
    6. var mV;
    7.  
    8. if(mV == 5){
    9. totaltxt++;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  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: Why isn't it working? About external JS

    I still don't understand what you are trying to do but I belive you approach the problem incorrectly. You're thinking in an imperative way rather than using the declarative engine at hand. If you want to animate the value of some label then you can do it this way:

    javascript Code:
    1. Text {
    2. property int value: 0
    3. id: total_txt
    4. text: value
    5. // ...
    6. Behavior on value {
    7. NumberAnimation {}
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    And then elsewhere in your app:

    javascript Code:
    1. total_txt.value = 5
    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.


  9. #9
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why isn't it working? About external JS

    Thank you for feedback but it isn't actually what I need. Because I want to do that: when my animation plays, when onExit works, a value (mV = 5) will turn what I added and javascript code will give this value to mV in total.js ; then because javascript code works, (text: Logic.totaltxt) totaltxt will take 1 instead of 0 and we will see 1 on screen instead of 0.

    I think that I can't tell what I mean because I'm new on qml

  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: Why isn't it working? About external JS

    Quote Originally Posted by Yonetici View Post
    Thank you for feedback but it isn't actually what I need. Because I want to do that: when my animation plays, when onExit works, a value (mV = 5) will turn what I added and javascript code will give this value to mV in total.js ; then because javascript code works, (text: Logic.totaltxt) totaltxt will take 1 instead of 0 and we will see 1 on screen instead of 0.
    What do you need it for? What is the ultimate goal you are trying to achieve? Why do you need the value to be a js variable and not a qml property?
    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
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why isn't it working? About external JS

    because if it works, it is very easy to applicate anywhere

Similar Threads

  1. How to use an external variable ?
    By Computer Hater in forum General Programming
    Replies: 10
    Last Post: 25th June 2011, 04:45
  2. QProcess & Working with External Programs
    By jstippey in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2010, 20:04
  3. Using external libraries
    By Handi in forum Newbie
    Replies: 5
    Last Post: 9th December 2010, 22:51
  4. Use external DLL ?
    By pl01 in forum Newbie
    Replies: 5
    Last Post: 10th November 2010, 14:48
  5. add external api
    By adamatic in forum Qt Programming
    Replies: 6
    Last Post: 16th April 2009, 10:25

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.