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. How to give JSON Object to QTScript
Forum Updated to NodeBB v4.3 + New Features

How to give JSON Object to QTScript

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 509 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
    Mesobius
    wrote on last edited by
    #1

    Hi all,

    I'm trying to set a variable in QTScript from a JSON Object. I explain my problem :

    I make CURL request to an external API RESTFULL. The API REST returns JSON Object or JSON Array. The CURL request works well. I get the right JSON result
    When the request is done, I need to give this result (Object or array) to a script in QTScript.
    My actual code is the following one :

    MyCurlConnexion curl ;
        // make cURL request
        QJsonObject jobj = curl.requestGet("https://localhost:8082/api/....................."); // request have been hidden for the forum
        // set
        QScriptValue array = engine->newArray(jobj.count());
        QStringList keylist = jobj.keys();
        for (int i=0; i<jobj.count(); i++) {
            array.setProperty(keylist.at(i),jobj.value(keylist.at(i)));
        }
        engine->globalObject().setProperty(QString("SqlResult"),array);
    

    This code is not fully tested, just to show the principal of the actual system.

    But if the JSON result is not a unique object, but an JSON array of JSON object, my code is not working.

    My Question : How can I send a "generic" JSON result to my QTScript ?
    is there a solution like this :

    engine->globalObject().setProperty(QString("SqlResult"),myjsonobject);
    

    or another way to solve my problem.

    Thanks for your help. BRs

    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