Important: Please read the Qt Code of Conduct -

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

  • 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

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

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

  • 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 ?

  • @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.

  • @Diracsbracket That was my problem here ! Thank you !

Log in to reply