Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Lost parameter value after call Q_INVOKABLE function from QML.
Qt 6.11 is out! See what's new in the release blog

Lost parameter value after call Q_INVOKABLE function from QML.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 576 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.
  • M Offline
    M Offline
    MintogoDeveloper
    wrote on last edited by
    #1

    I have a problem of calling Q_INVOKABLE function.

    in QML

    function doSomeThing(intList, jsonObject)
    {
        classItem.someFunction(intList, jsonObject)
    }
    ...
    var arr = []
    arr.push(1)
    arr.push(2)
    
    var json = {some data}
    
    doSomeThing(arr, json)
    

    in H

    ...
    Q_INVOKABLE void doSomethingFunction(QVector<int> intList, QJsonObject object = QJsonObject());
    ...
    

    in CPP Class

    ...
    void Class::doSomethingFunction(QVector<int> intList, QJsonObject object)
    {
      // do some thing with parameters
    }
    ...
    

    in CPP part, the parameter int list value had been changed to (0).

    I can not understand.

    When I include int list to Json, array data is alright, it's fine.

    Is anyone has some idea?

    thank you.

    J.HilkJ 1 Reply Last reply
    0
    • M MintogoDeveloper

      I have a problem of calling Q_INVOKABLE function.

      in QML

      function doSomeThing(intList, jsonObject)
      {
          classItem.someFunction(intList, jsonObject)
      }
      ...
      var arr = []
      arr.push(1)
      arr.push(2)
      
      var json = {some data}
      
      doSomeThing(arr, json)
      

      in H

      ...
      Q_INVOKABLE void doSomethingFunction(QVector<int> intList, QJsonObject object = QJsonObject());
      ...
      

      in CPP Class

      ...
      void Class::doSomethingFunction(QVector<int> intList, QJsonObject object)
      {
        // do some thing with parameters
      }
      ...
      

      in CPP part, the parameter int list value had been changed to (0).

      I can not understand.

      When I include int list to Json, array data is alright, it's fine.

      Is anyone has some idea?

      thank you.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @MintogoDeveloper
      your JS array will be converted automatically to a QVariantList wenn passed to c++

      try that as argument and not a QVector<int> that conversion probably fails
      https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qvariantlist-and-qvariantmap-to-javascript-array-and-object


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @MintogoDeveloper
        your JS array will be converted automatically to a QVariantList wenn passed to c++

        try that as argument and not a QVector<int> that conversion probably fails
        https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qvariantlist-and-qvariantmap-to-javascript-array-and-object

        M Offline
        M Offline
        MintogoDeveloper
        wrote on last edited by
        #3

        @J-Hilk Thank you, problem was conversion of data type between QML and Qt(C++).

        I resolved it. :)

        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