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. c++ does reads QList<QString> always empty when sent from QML
Forum Updated to NodeBB v4.3 + New Features

c++ does reads QList<QString> always empty when sent from QML

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 478 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    hello guys,

    I have this:
    qml file:

    property variant sapSystems:    [{"a": 1, "b": 2, "c": 3},
                                             {"a": 4, "b": 5, "c", 6}]
        Component.onCompleted: {
            var neco = cpp.connectionTest(sapSystems[1]);    // so im sending: {"a": 4, "b": 5, "c", 6}
        }
    

    and in c++ file i have:

    void CPP::connectionTest(QList<QString> connParameters)
    {
    qDebug() << connParameters;    // debugs "QList()"
    qDebug() << connParameters.count() << connParameters.size() << connParameters.length();    // debugs: 0 0 0
    foreach(auto &x,connParameters)    // debugs 0 as connParameters seems to be empty
        qDebug() << x;
    }
    

    howcome on C++ side its empty?

    jsulmJ 1 Reply Last reply
    0
    • S shokarta

      hello guys,

      I have this:
      qml file:

      property variant sapSystems:    [{"a": 1, "b": 2, "c": 3},
                                               {"a": 4, "b": 5, "c", 6}]
          Component.onCompleted: {
              var neco = cpp.connectionTest(sapSystems[1]);    // so im sending: {"a": 4, "b": 5, "c", 6}
          }
      

      and in c++ file i have:

      void CPP::connectionTest(QList<QString> connParameters)
      {
      qDebug() << connParameters;    // debugs "QList()"
      qDebug() << connParameters.count() << connParameters.size() << connParameters.length();    // debugs: 0 0 0
      foreach(auto &x,connParameters)    // debugs 0 as connParameters seems to be empty
          qDebug() << x;
      }
      

      howcome on C++ side its empty?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @shokarta said in c++ does reads QList<QString> always empty when sent from QML:

      [{"a": 1, "b": 2, "c": 3},
      {"a": 4, "b": 5, "c", 6}]

      This is not a list of strings, but a list of objects. So, sapSystems[1] is {"a": 4, "b": 5, "c", 6} which is not a string.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        shokarta
        wrote on last edited by
        #3

        Right, you totaly right...
        but QList<QObject> cant be passed to c++ as wrong conversion...

        any idea how to do what im trying to do?

        jsulmJ 1 Reply Last reply
        0
        • S shokarta

          Right, you totaly right...
          but QList<QObject> cant be passed to c++ as wrong conversion...

          any idea how to do what im trying to do?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @shokarta I'm not QML expert, but maybe QList<QVariant>? Or QList<QJsonObject>?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @shokarta I'm not QML expert, but maybe QList<QVariant>? Or QList<QJsonObject>?

            S Offline
            S Offline
            shokarta
            wrote on last edited by shokarta
            #5

            @jsulm said in c++ does reads QList<QString> always empty when sent from QML:

            QList<QJsonObject>

            TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
            

            i dont know how to pass this objects and read it from c++ :(
            unless sending JSON string and recreate it to JSON... which to me is very unnecessary bad practice :(
            I would realy prefer to send it and read it in any compatibile way

            jsulmJ 1 Reply Last reply
            0
            • S shokarta

              @jsulm said in c++ does reads QList<QString> always empty when sent from QML:

              QList<QJsonObject>

              TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
              

              i dont know how to pass this objects and read it from c++ :(
              unless sending JSON string and recreate it to JSON... which to me is very unnecessary bad practice :(
              I would realy prefer to send it and read it in any compatibile way

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @shokarta Actually it should be QJsonObject (since {"a": 4, "b": 5, "c", 6} is not a list of objects but an object)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • jsulmJ jsulm

                @shokarta Actually it should be QJsonObject (since {"a": 4, "b": 5, "c", 6} is not a list of objects but an object)

                S Offline
                S Offline
                shokarta
                wrote on last edited by
                #7

                @jsulm said in c++ does reads QList<QString> always empty when sent from QML:

                QJsonObject

                but QJsonObject give the very same error:

                TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
                
                jsulmJ 1 Reply Last reply
                0
                • S shokarta

                  @jsulm said in c++ does reads QList<QString> always empty when sent from QML:

                  QJsonObject

                  but QJsonObject give the very same error:

                  TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @shokarta Then try QVariant and try to cast to QJsonObject using https://doc.qt.io/qt-6/qvariant.html#toJsonObject

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @shokarta Then try QVariant and try to cast to QJsonObject using https://doc.qt.io/qt-6/qvariant.html#toJsonObject

                    S Offline
                    S Offline
                    shokarta
                    wrote on last edited by
                    #9

                    @jsulm QVariant debugs empty in CPP, so no converion possible :(

                    S 1 Reply Last reply
                    0
                    • S shokarta

                      @jsulm QVariant debugs empty in CPP, so no converion possible :(

                      S Offline
                      S Offline
                      shokarta
                      wrote on last edited by
                      #10

                      so at the end I converted that object array to JSON in QML, send it to C++, and in CPP recreated to JSON...
                      bad practice but lets say ifs short code working, probably fast too

                      1 Reply Last reply
                      0
                      • S shokarta has marked this topic as solved on

                      • Login

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