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. alternative for QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap())?
Forum Updated to NodeBB v4.3 + New Features

alternative for QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap())?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.1k Views 2 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.
  • J Offline
    J Offline
    Jens van koolwijk
    wrote on last edited by Jens van koolwijk
    #1

    I am trying to send json data between QML and C++ trough signal and slot.I don't want to stringily json.

    Now I use this. is there a easier way ?

    //qml
    signal sendResponse(var data);

    //c++
    QObject::connect(this->objects[reference], SIGNAL(sendResponse(QVariant)), this, SLOT(parseResponse(QVariant)));

    void DisplayInterface::parseResponse(QVariant data)
    {
    qDebug() << QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap());
    }

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @Jens-van-koolwijk,

      qDebug() << QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap());

      I'm not familiar with QML, nor QJSValue, but just from the docs, I'd start with something like:

      qDebug() << data.type() << data.typeName();
      qDebug() << data.toJsonObject();
      qDebug() << data.toJsonObject().toVariantMap();
      

      What does that output?

      Cheers.

      J 1 Reply Last reply
      0
      • Paul ColbyP Paul Colby

        Hi @Jens-van-koolwijk,

        qDebug() << QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap());

        I'm not familiar with QML, nor QJSValue, but just from the docs, I'd start with something like:

        qDebug() << data.type() << data.typeName();
        qDebug() << data.toJsonObject();
        qDebug() << data.toJsonObject().toVariantMap();
        

        What does that output?

        Cheers.

        J Offline
        J Offline
        Jens van koolwijk
        wrote on last edited by Jens van koolwijk
        #3

        @Paul-Colby

        output:
        QVariant::QWidget* QJSValue
        QJsonObject()
        QMap()

        Paul ColbyP 1 Reply Last reply
        0
        • J Jens van koolwijk

          @Paul-Colby

          output:
          QVariant::QWidget* QJSValue
          QJsonObject()
          QMap()

          Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by
          #4

          @Jens-van-koolwijk said:

          QVariant::QWidget* QJSValue

          Ah, so you'll need to use QVariant::toJSValue first, eg:

          qDebug() << data.type() << data.typeName();
          qDebug() << data.toJsonValue().type() << data.toJsonValue();
          qDebug() << data.toJsonValue().toObject();
          qDebug() << data.toJsonValue().toObject().toVariantMap();
          

          See if that works.

          J 1 Reply Last reply
          0
          • Paul ColbyP Paul Colby

            @Jens-van-koolwijk said:

            QVariant::QWidget* QJSValue

            Ah, so you'll need to use QVariant::toJSValue first, eg:

            qDebug() << data.type() << data.typeName();
            qDebug() << data.toJsonValue().type() << data.toJsonValue();
            qDebug() << data.toJsonValue().toObject();
            qDebug() << data.toJsonValue().toObject().toVariantMap();
            

            See if that works.

            J Offline
            J Offline
            Jens van koolwijk
            wrote on last edited by Jens van koolwijk
            #5

            @Paul-Colby

            output:
            QVariant::QWidget* QJSValue
            0 QJsonValue(null)
            QJsonObject()
            QMap()

            Hello Paul.

            I've read
            Qt 5.3 changed the mapping of "var" parameters in QML declared signals to QJSValue. This was reverted
            to the behavior of earlier Qt versions to use QVariant. The original issue
            of not being able to pass function objects through var parameters of QML
            declared signals is solved by wrapping a QJSValue inside the Variant.

            So i have to do this
            QJsonObject::fromVariantMap(data.value<QJSValue().toVariant().toMap());

            But to get json from QML to c++ this looks a little bit ugly to me.

            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