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. Send QVariantList and QVariantMap to JavaScript Array and Object
Forum Updated to NodeBB v4.3 + New Features

Send QVariantList and QVariantMap to JavaScript Array and Object

Scheduled Pinned Locked Moved QML and Qt Quick
19 Posts 3 Posters 10.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.
  • B Offline
    B Offline
    beh_zad
    wrote on last edited by
    #6

    thank for replying me again, I have done with this view type and get this error again.
    bq. error: no matching function for call to 'QMetaObject::invokeMethod(QGraphicsObject*, const char [11], QArgument<QVariant>, QArgument<QVariant>)'
    Q_ARG(QVariant, QVariant::fromValue(map)));
    ^

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #7

      Hi,

      bq. “error: no matching function for call to ‘QMetaObject::invokeMethod(QQuickItem*, const char [11], QArgument<QVariant>, QArgument<QVariant>)’ Q_ARG(QVariant, QVariant::fromValue(map)));

      @
      Item {
      function readValues(anArray, anObject) {
      for (var i=0; i<anArray.length; i++)
      console.log("Array item:", anArray[i])
      for (var prop in anObject) {
      console.log("Object item:", prop, "=", anObject[prop])
      }
      }
      }
      @

      Does your Item element have a parent ? In other words, is the Item element inside another Component ?

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beh_zad
        wrote on last edited by
        #8

        No, it isn't inside the another Component

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #9

          Ok. Then include this in main.cpp
          @
          #include <QtQuick>
          @

          157

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beh_zad
            wrote on last edited by
            #10

            Thanks for replying, but the error occurred again.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #11

              Are you still using QQuickView ? Why is there QGraphicsObject in error ?

              bq. QMetaObject::invokeMethod(QGraphicsObject*, const char [11], QArgument<QVariant>, QArgument<QVariant>)’ Q_ARG(QVariant, QVariant::fromValue(map)));

              157

              1 Reply Last reply
              0
              • B Offline
                B Offline
                beh_zad
                wrote on last edited by
                #12

                the whole codes is :

                in main.cpp

                #include <QtCore>
                #include <QtDeclarative>

                @int main(int argc, char *argv[])
                {
                QGuiApplication app(argc, argv);

                QDeclarativeView view(QUrl::fromLocalFile&#40;"qrc:///main.qml"&#41;);
                
                QVariantList list;
                list << 10 << QColor(Qt::green) << "bottles";
                
                QVariantMap map;
                map.insert("language", "QML");
                map.insert("released", QDate(2010, 9, 21));
                
                QMetaObject::invokeMethod( view.rootObject(), "readValues",
                                          Q_ARG(QVariant, QVariant::fromValue(list)),
                                          Q_ARG(QVariant, QVariant::fromValue(map)));
                
                view.setSource(QUrl::fromLocalFile&#40;"qrc:///main.qml"&#41;);
                view.show();
                
                return app.exec();
                

                }@

                in main.qml

                @import QtQuick 2.2
                import QtQuick.Window 2.1

                Item {
                function readValues(anArray, anObject) {
                for (var i=0; i<anArray.length; i++)
                console.log("Array item:", anArray[i])

                    for (var prop in anObject) {
                        console.log("Object item:", prop, "=", anObject[prop])
                    }
                }
                

                }@

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #13

                  @
                  QDeclarativeView view(QUrl::fromLocalFile("qrc:///main.qml"));
                  @

                  Don't use QDeclarativeView; use QQuickView instead.

                  Your earlier code was correct:
                  @
                  #include <QGuiApplication>
                  #include <QtQuick>

                  int main(int argc, char *argv[])
                  {
                  QGuiApplication app(argc, argv);

                  QQuickView view(QUrl::fromLocalFile&#40;"main.qml"&#41;);
                   
                  QVariantList list;
                  list << 10 << QColor(Qt::green) << "bottles";
                   
                  QVariantMap map;
                  map.insert("language", "QML");
                  map.insert("released", QDate(2010, 9, 21));
                   
                  QMetaObject::invokeMethod(view.rootObject(), "readValues",
                          Q_ARG(QVariant, QVariant::fromValue(list)),
                          Q_ARG(QVariant, QVariant::fromValue(map)));
                   
                  view.show();
                  return app.exec();
                  

                  }
                  @

                  Try with this code again and check.

                  157

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    beh_zad
                    wrote on last edited by
                    #14

                    but this code show this error:
                    error: no matching function for call to 'QMetaObject::invokeMethod(QQuickItem*, const char [11], QArgument<QVariant>, QArgument<QVariant>)'
                    Q_ARG(QVariant, QVariant::fromValue(map)));

                    I tried it again but this error is displayed

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #15

                      Strange.. It works perfectly for me. Which Qt version and OS are you using ?

                      157

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        beh_zad
                        wrote on last edited by
                        #16

                        It's storage for me too, Qt Creater 3.1.1 based on Qt 5.2.1

                        1 Reply Last reply
                        0
                        • p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #17

                          Can you RightClick on QMetaObject > Refactor > Add #Includes ... (any or all which it mentions) ?

                          157

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            beh_zad
                            wrote on last edited by
                            #18

                            I had done it at least, it needs to include <QQuickItem>, thanks for everybody to replying my question.

                            1 Reply Last reply
                            0
                            • p3c0P Offline
                              p3c0P Offline
                              p3c0
                              Moderators
                              wrote on last edited by
                              #19

                              Good... Happy Coding :)

                              157

                              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