Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ReferenceError: "..." is not defined
Forum Updated to NodeBB v4.3 + New Features

ReferenceError: "..." is not defined

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patcs
    wrote on 10 Apr 2017, 09:23 last edited by
    #1

    Im trying run this code, and it lunch the error: ReferenceError: "vi" is not defined. someone who can help me, please?

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.1
    import QtQml 2.2

    Window {
    id: window
    visible: true
    visibility: "FullScreen"

    Item{
        property double xb: 0;
        property double yb: 0;
        property double vx: 0;
        property double vy: 0;
        property int tita: 45;
        property int vi: 20;
        property double g: 9.8;
    
        Timer {
            id:time
            interval: 500
            repeat: true
            running: true
            onTriggered:{
                vx = vi*cos(tita);
                vy = vi*sin(tita)-(g*time);
                xb =  vi*cos(tita)*time;
                yb = vi*sen(tita)*time-(1/2*(g*(time^2)));
                console.log(vx,vy,xb,yb)
            }
    
        }
    
    }
    
    
    
    
    
    
    
    Background{
    id: background
    }
    
    Bird{
    id: bird
    x: 20
    y: 600
    
        Behavior on x{
            NumberAnimation{
            duration: 600
    
    
            }
        }
    
    }
    
    MouseArea{
        anchors.fill: parent
        onClicked: {
            bird.z = bird.z +1
            bird.x= 1000
        }
    }
    

    Button {
    text: "Salir"
    onClicked: window.close()

    }
    

    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prasoon1338
      wrote on 10 Apr 2017, 11:33 last edited by
      #2

      Please try to give id for your "Item" element, and try to access vi with "item_id.vi"

      Item{
        id: myItem
        .... ..... ...
      }
      
      Timer{
       ....
       onTriggered :{
         myItem.vx = myItem.vi * cos(myItem.tita)
       }
      }
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        patcs
        wrote on 11 Apr 2017, 06:40 last edited by patcs 4 Nov 2017, 08:13
        #3

        Thank you, but it doesnt work! It works if I declare variables inside of the timer, but Im not sure if this are going to have any repercurssion in my final result.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pradeep P N
          wrote on 11 Apr 2017, 08:55 last edited by Pradeep P N 4 Nov 2017, 09:01
          #4

          Hi Patcs,

          Move the Timer out of Item and use Math operation as bellow

          Window {
          id: window
          visible: true

          // Item{
          property double xb: 0;
          property double yb: 0;
          property double vx: 0;
          property double vy: 0;
          property int tita: 45;
          property int vi: 20;
          property double g: 9.8;

              Timer {
                  id:time
                  interval: 500
                  repeat: true
                  running: true
                  onTriggered:{
                      vx = vi * Math.cos(tita);
                      vy = vi * Math.sin(tita)-(g*time);
                      xb = vi * Math.cos(tita) * time;
                      yb = vi * Math.sin(tita) * time-(1/2*(g*(time^2)));
                      console.log(vx,vy,xb,yb)
                  }
              }
          

          // }
          }

          The properties belongs to Window. And what you represent "time" in your calculation. time is id for Timer

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          1 Reply Last reply
          1
          • P Offline
            P Offline
            patcs
            wrote on 11 Apr 2017, 09:16 last edited by
            #5

            I was trying and the only solution that I found was this:

            import QtQuick 2.6
            import QtQuick.Window 2.2
            import QtQuick.Controls 2.1
            import QtQml 2.2

            Window {
            id: window
            visible: true
            visibility: "FullScreen"

            Item{

            Timer {
                id:time
                interval: 500
                repeat: true
                running: true
            
                property double xb: 0;
                property double yb: 0;
                property double vx: 0;
                property double vy: 0;
                property int tita: 45;
                property int vi: 20;
                property double g: 9.8;
            
                onTriggered:{
                    vx = vi*cos(tita);
                    vy = vi*sin(tita)-(g*time);
                    xb =  vi*cos(tita)*time;
                    yb = vi*sen(tita)*time-(1/2*(g*(time^2)));
                    console.log(vx,vy,xb,yb)
                }
            
            }
            

            }

            Background{
            id: background
            }

            Bird{
            id: bird
            x: 20
            y: 600

            Behavior on x{
                NumberAnimation{
                duration: 600
            
            
                }
            }
            

            }

            MouseArea{
            anchors.fill: parent
            onClicked: {
            bird.z = bird.z +1
            bird.x= 1000
            }
            }
            Button {
            text: "Salir"
            onClicked: window.close()

            }
            }

            So, if someone need the solution, i found this, however I dont know if it is the best one. Thank you to everyone who have helped me!

            1 Reply Last reply
            0

            1/5

            10 Apr 2017, 09:23

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved