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. Javascript error: cant find variable:(
Forum Updated to NodeBB v4.3 + New Features

Javascript error: cant find variable:(

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    ReshmaS
    wrote on last edited by
    #1

    I have a qml file and I am checking for some condition in js file. I imported the js file as Coco in my qml file, and while cheking the condition I gave Coco.function();. an error in the js file "cant find reference variable". The variable is still available in my qml file. I am sure that this is a silly error but am breaking my head off with this. ANy help is appreciated.

    Reshma

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      please post some code

      dmcr

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ReshmaS
        wrote on last edited by
        #3

        JS file

        @function val()

        {
        param_value.text=text_input1.text

        }

        function func() {

        if(param_value.text < "70"*1)
          {
            param_value.color="red"
          param_value.font.bold=true
            dialog.visible=true
        
        }
        else
        

        {
        param_value.color="black"
        param_value.font.bold=false
        dialog.visible=false
        }

        }
        @

        in qml file

        //

        @
        TextEdit {
        id: param_value
        width: 70
        height: 15
        text:slider.slidervalue
        onTextChanged: Coco.func();

                            font.pixelSize: 12
                        }@
        

        onClicked: {param_value.text=slider.slidervalue;
        Coco.func();
        }
        error i get is: reference error: cant find variable param_value

        Reshma

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmcr
          wrote on last edited by
          #4

          Better than having your id in the javascript, you can pass the id as a parameter

          dmcr

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ReshmaS
            wrote on last edited by
            #5

            sorry dmcr, I did not understand. cud u just quote an example. Thanks

            Reshma

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dmcr
              wrote on last edited by
              #6

              i don't know exactly where is your problem since you don't gave the full code with header, etc...

              What i was suggesting is just a better manner :
              instead of func() {.....
              create a function func_(componentId){....
              where you can then update values componentId.text = ....

              dmcr

              1 Reply Last reply
              0

              • Login

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