Important: Please read the Qt Code of Conduct -

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":
    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": 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("Cs Value",ui->csValue_Text->displayText());

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

    // QFileDialog::DialogLabel::FileType;
    if( | QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))

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

Log in to reply