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. How send me data json from QML in C++?
Forum Updated to NodeBB v4.3 + New Features

How send me data json from QML in C++?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 4.7k 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.
  • T Offline
    T Offline
    Trikrista
    wrote on last edited by
    #1

    I tried make this so:
    @
    //main.qml
    Rectangle {
    //---
    signal sgSendJSON(var v)
    function sendJSON() {
    var v = {title: "text", text: "text"}
    sgSendJSON(v)
    }
    //---
    }

    //main.cpp
    //---
    pView = new QQuickView;
    QObject *pObject = pView->rootObject();

    connect(pObject, SIGNAL(sgSendJSON(QVariant)), this, SLOT(SendJSON(QVariant)));
    //---
    @

    But I failed(

    I'm sorry for my bad English

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Please describe what you mean by "failed". Did your application fail to compile? Did it compile but the rectangle failed to show up? Or ...?

      Anyway, see "Connecting C++ Objects to QML Objects":http://doc.qt.io/qt-5/signalsandslots-syntaxes.html#connecting-c-objects-to-qml-objects

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Trikrista
        wrote on last edited by
        #3

        The program runs without errors.

        But I don't sure that correctly choose parameter slot and signal (QVariant).
        And I don't know what get data JSON from QVariant.

        I'm sorry for my bad English

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

          Hi,

          @
          var v = {title: "text", text: "text"}
          @

          I think this is not a JSON format as the key should be a string format i.e in "".
          Its more like a map which you can convert to on C++ side
          @
          void SendJSON(QVariant v) {
          qDebug() << v.toMap();
          }
          @

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SpongeBernd
            wrote on last edited by
            #5

            You can get the JavaScript object's property values like that:

            @
            void SendJSON(QVariant v) {
            QString title = v.toMap().value("title").toString();
            QString text = v.toMap().value("text").toString();
            }
            @

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Trikrista
              wrote on last edited by
              #6

              Thanks. This is what I need

              I'm sorry for my bad English

              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