Saving Json[solved]



  • I have a program that uses a ton of fields for a user to input information and i want to save it as Json and help on what i should use that will make the saved file appear in the correct Json format too.


  • Moderators

    i think the esiest way would be to use "QJson library":http://qjson.sourceforge.net
    It lets you convert QVariants (QLists, QMaps, ...) convert to JSON.


  • Moderators

    Qt5 has a build-in QJson* set of classes, you can use those, too. Written mostly by Lars, they are lightweight and very fast. See "the docs":http://qt-project.org/doc/qt-5.0/qtcore/json.html for more info.



  • @sessionObject.insert("Camera", ui->camera->currentText());
    sessionObject.insert("Energy Filter Slit Size", ui->energyFilterSlitSize_Text->displayText());
    sessionObject.insert("Acquisition Software",ui->acquistionSoftware->currentText());
    sessionObject.insert("Voltage",ui->voltage_Text->displayText());
    sessionObject.insert("Cs Value",ui->csValue_Text->displayText());

    sessionModel.insert("TEM 2D",sessionObject);
    
    QJsonDocument sessionDoc = QJsonDocument(sessionObject);
    sessionDoc.setObject(sessionModel);
    
    QFile file;
    QString filename = QFileDialog::getSaveFileName(this, "Save file", "" ,"");
    

    // QFileDialog::DialogLabel::FileType;
    file.setFileName(filename);
    if(file.open(QFile::ReadOnly | QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
    {
    file.write(sessionDoc.toJson());
    file.close();
    }

    QMessageBox::information(0, QString("Gopher"), QString("You Were Successful!")
                             , QMessageBox::Ok);
    exit(0);@

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.