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. Can't use C++ method in Qml side : Insufficient arguments
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 3.9k 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by
    #1

    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

    tracymaT 1 Reply Last reply
    0
    • D DavidM29

      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

      tracymaT Offline
      tracymaT Offline
      tracyma
      wrote on last edited by
      #2

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

      1 Reply Last reply
      3
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3

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

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

          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 ?

          DiracsbracketD 1 Reply Last reply
          0
          • D DavidM29

            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 ?

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by Diracsbracket
            #5

            @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
            2
            • DiracsbracketD 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 Offline
              D Offline
              DavidM29
              wrote on last edited by
              #6

              @Diracsbracket That was my problem here ! Thank you !

              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