Skip to content
QtWS25 Last Chance
  • 0 Votes
    4 Posts
    155 Views
    JonBJ
    @Poggar As the above two posts have said. Fastest way to convert Vector to QJsonArray? gives code and confirms there is no faster way than some sort of iteration over the C++ array adding elements to the JSON array, you can use std::copy() to save you writing a for loop yourself if you wish.
  • 0 Votes
    30 Posts
    3k Views
    S
    @SGaist I actually have some of them built already. Thats why i was asking what would be better/ if my approach with the database would be viable. :) Have a nice easter.
  • QMap exposed as QProperty gives qml undefined

    Solved QML and Qt Quick qmap qml qml json
    2
    0 Votes
    2 Posts
    386 Views
    MesrineM
    @Saviz I think is not possible to expose a QMap directly to QML, https://doc.qt.io/qt-6/qtqml-cppintegration-data.html#sequence-type-to-javascript-array Maybe one should use a QVariantMap https://doc.qt.io/qt-6/qtqml-cppintegration-data.html#qvariantlist-and-qvariantmap-to-javascript-array-and-object
  • 0 Votes
    5 Posts
    424 Views
    Paul ColbyP
    HI @R-P-H , Besides converting the QByteArray to a QString, how would I extract the value if I added {} to the QByteArray ... As long as the QByteArray contains a valid JSON value, you can either wrap it in [ and ] to make it a JSON array, or { "key": and } to make it a JSON object. If wrapping in an array, you would then fetch the first array item to get the original JSON value. Of if wrapping in an object, fetch the value corresponding to the key you used in the wrapper. Here's a complete example: const QByteArray json{ "\"My Value\" "}; qDebug().noquote() << "input " << json; qDebug().noquote() << "parse-as-is " << QJsonDocument::fromJson(json); // Will fail. const QJsonDocument arrayDoc = QJsonDocument::fromJson("[" + json + "]"); qDebug().noquote() << "wrapped-in-array " << arrayDoc; qDebug().noquote() << "unwrapped-array " << arrayDoc.array().at(0); const QJsonDocument objectDoc = QJsonDocument::fromJson("{ \"value\": " + json + "}"); qDebug().noquote() << "wrapped-in-object " << objectDoc; qDebug().noquote() << "unwrapped-object " << objectDoc.object().value(QStringLiteral("value")); Which outputs: input "My Value" parse-as-is QJsonDocument() wrapped-in-array QJsonDocument(["My Value"]) unwrapped-array QJsonValue(string, My Value) wrapped-in-object QJsonDocument({"value":"My Value"}) unwrapped-object QJsonValue(string, My Value) Cheers.
  • 0 Votes
    6 Posts
    1k Views
    R
    After playing around using postman I found the issue. When sending a Bearer: "" or Bearer: "xxxxxx" token, the server returns "Authentication Required". But when sending no Bearer token or an empty Bearer: it works fine. So when logging in; no token must be supplied else it tries to authenticate against that token instead of correctly generating a new one provided you submitted valid credentials in the JSON body. Seems a bit odd to me, but ok.
  • 0 Votes
    1 Posts
    165 Views
    No one has replied
  • how can i modify the value of the Qjason array?

    Unsolved General and Desktop json qjsonarray
    4
    0 Votes
    4 Posts
    1k Views
    JonBJ
    @CupofCoffee said in how can i modify the value of the Qjason array?: TradingAreaInfoArr = rootObj["TradingAreaInfo"].toArray(); My understanding is that this returns a copy of the QJsonArray. You can modify that copy (update values, append new ones), but that does not alter the array in the QJsonDocument. The same with the QJsonObject InfoObj = rootObj["info"].toObject(); The objects/arrays in these are read-only. You have to copy them out as above, alter them, and then replace the current objects/arrays in the document, or create a new one, in order to produce a new document with the updates which can be saved.
  • 0 Votes
    14 Posts
    6k Views
    H
    I did resolve it using rapidjson instead of QJsonObject Thank you all
  • 0 Votes
    1 Posts
    469 Views
    No one has replied
  • How to exploit a json file in QT ?

    Unsolved General and Desktop json cpp
    28
    0 Votes
    28 Posts
    5k Views
    F
    @jsulm said in How to exploit a json file in QT ?: @feedain You already have this code snippet here, did you notice it? obj["State"] = int(state); yes thanks
  • Reach the spesific element of Json Array

    Solved General and Desktop qt5 json
    13
    0 Votes
    13 Posts
    1k Views
    D
    @JonB I produced my Json. It make sense i will edit my json and write without " "
  • Replace and Remove from html string not working

    Solved General and Desktop qstring html json
    5
    0 Votes
    5 Posts
    942 Views
    R
    @JKSH Oh wow, you're completely right. I didn't know qDebug() behaved like this, I assumed noquote() was the default. Thanks for the help, I don't know how long it would have taken me to find out.
  • write to a different file each time of run

    Solved General and Desktop qt5 json write
    7
    0 Votes
    7 Posts
    1k Views
    D
    @J-Hilk thank you
  • Read from Json in an order

    Solved General and Desktop qt5 json jsonparser
    9
    0 Votes
    9 Posts
    1k Views
    D
    @jsulm thank you. I did it with your solution. It works fine.
  • How to parse such a complex json file

    Solved General and Desktop qt5 json read
    10
    0 Votes
    10 Posts
    3k Views
    R
    @suslucoder The "Plan" array is a little unusual because the objects it contains are not all of the same structure. Usually, arrays should contain a sequence of elements of the same type. However, it is legal JSON. If you are certain that the first element of the "Plan" array will have the structure as in your example above, you can perhaps rely on the others to all have the 2nd type structure. Otherwise, you might need to check for the existence of certain keys -- for example, by using the function QJsonObject::contains() to determine which kind of object it is.
  • Creating json file with subroot

    Unsolved General and Desktop json root qt5
    13
    0 Votes
    13 Posts
    1k Views
    D
    @KroMignon thank you