Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved Can't use C++ method in Qml side : Insufficient arguments

    QML and Qt Quick
    3
    6
    2489
    Loading More Posts
    • 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.
    • D
      DavidM29 last edited by

      Hello,
      I have made a C++ class that I use to make some calculation.
      I this class I have some INVOKABLE methods. I exposed the C++ by registering it as a type with this line :

         qmlRegisterType<Calculs>("CustomControls", 1, 0, "Calculs");
      

      I'm trying to use thos method in the main so I added a component "Calculs" with an id in the main.qml, then I call it from a Js function. My problem comes when the function is called. I have this error :

      Error: Insufficient arguments
      

      My C++ method use 3 double as input arguments, when I call my function I use this line :

      var result = calc.getValue(1,2,3)
      

      I don't really understand how could I have insufficient argument with this line.

      Does anybody have a clue ?

      Thank you in advance

      tracyma 1 Reply Last reply Reply Quote 0
      • tracyma
        tracyma @DavidM29 last edited by

        @DavidM29 try var result = calc.getValue(1.0, 2.0, 3.0)

        1 Reply Last reply Reply Quote 3
        • D
          DavidM29 last edited by

          @tracyma seems to works, thank you I belive it is due to format issu when I call the method.

          1 Reply Last reply Reply Quote 0
          • D
            DavidM29 last edited by

            Finally as soon as I use a variable from a TextField it does the same thing.

            Here is how I convert the text to float :

             var floatValue= parseFloat(myTextField.getText())
            

            I'm not sure the conversion works properly.
            Is there any problem using this as a variable of my method ?

            Diracsbracket 1 Reply Last reply Reply Quote 0
            • Diracsbracket
              Diracsbracket @DavidM29 last edited by Diracsbracket

              @DavidM29
              You must use myTextField.text or myTextField.displayText to get the text. Both these are QML properties. getText() is a QML method, which does something else than you probably think it does, and which requires arguments, hence the error.

              D 1 Reply Last reply Reply Quote 2
              • D
                DavidM29 @Diracsbracket last edited by

                @Diracsbracket That was my problem here ! Thank you !

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post