Skip to content
QtWS25 Call for Papers
  • 0 Votes
    3 Posts
    191 Views
    M

    @Christian-Ehrlicher Ok, thank you so much :)

  • 0 Votes
    5 Posts
    764 Views
    A

    @JonB
    sorry for late reply. you suggestion worked well.
    i followed https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application and modified my code according to that. now at sender side looks like this

    QJsonDocument doc1; QFile j("/home/first.JSON"); if(j.exists()) { if(j.open(QIODevice:: ReadOnly| QIODevice::Text)) { jstr=j.readAll(); doc1= QJsonDocument::fromJson(jstr.toUtf8()); } j.close(); QDataStream clientStream(socket); clientStream.setVersion(QDataStream::Qt_5_7); // Create the JSON we want to send QJsonObject message; message[QStringLiteral("type")] = QStringLiteral("message"); clientStream << QJsonDocument(doc1).toJson(); } } else { ui->l_err->show(); ui->l_err->setText("Connection refused. Please check server."); }

    and used server application from the link above at receiver end.
    this works well. I have tested this with JSON file having 3000 object. Will this work for 50,000 samples and more possibly 1500000 objects?

  • 0 Votes
    2 Posts
    5k Views
    ?

    Hi @LuisAbreu!

    I cannot confirm this. Are you sure your json file is valid? The following works for me:

    ============================================
    Json file:

    { "className": "ShoppingCart", "closedOn": "Fri Mar 27 15:52:13 2015", "coupon_count": "0", "createdOn": "Fri Mar 27 15:51:09 2015", "list": [ { "_className": "Product", "discount": "0", "fromyoubeep": "1", "has_alarm": 0, "id": "5601151333457", "intendedQuantity": 0, "isReady": "1", "isUnknown": "0", "loyaltyCredit": -1, "min_age": 0, "name": "Sumo Compal Cl<C3><A1>ssico Tutti-Fruti 1lt", "userCreated": "0", "weight": "0" }, { "_className": "Product", "fromyoubeep": "0", "has_alarm": 0, "id": "", "intendedQuantity": 0, "isReady": "1", "isUnknown": "0", "userCreated": "0", "weight": "0" } ], "loyaltyCard": { "_className": "LoyaltyCard", "barcode": "2446037038353", "barcodeType": "EAN13", "discount": "0", "fromyoubeep": "1", "has_alarm": 0, "id": "2446037038353", "intendedQuantity": 0, "isReady": "1", "isUnknown": "0", "loyaltyCredit": 0, "min_age": 0, "name": "Cart<C3><A3>o Poupa Mais", "price": "0", "product_id": "-1", "quantity": "0", "quantityValidated": "0", "state": "0", "type": 1, "userCreated": "0", "weight": "0" }, "mobile_checkout": "1" }

    ============================================
    C++ code:

    QFile file("/home/pw/file.json"); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "file error"; return; } const QByteArray ba = file.readAll(); file.close(); QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(ba, &err); qDebug() << err.errorString(); qDebug() << err.offset; QJsonObject sett2 = doc.object(); qDebug() << sett2.isEmpty(); QJsonObject sett3 = sett2.value(QString("loyaltyCard")).toObject(); qDebug() << sett3.isEmpty(); QJsonValue sett4 = sett3.value(QString("barcode")); qDebug() << sett4.toString();

    ============================================
    Cheers!

  • 0 Votes
    5 Posts
    3k Views
    ?

    Hi,
    IMHO the problem is that QJsonValue QJsonValue::​fromVariant(const QVariant & variant) (http://doc.qt.io/qt-5/qjsonvalue.html#fromVariant) can't convert BookMark to QJsonObject. I don't think that adding a custom converter with QMetatype::registerConverter() would help. Looks like you have to do the conversion to QJsonArray yourself.
    Cheers!
    Wieland