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. Saving Json[solved]

Saving Json[solved]

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.3k 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.
  • G Offline
    G Offline
    GreenFire
    wrote on 10 May 2013, 13:47 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 10 May 2013, 13:55 last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 10 May 2013, 19:09 last edited by
        #3

        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.

        (Z(:^

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GreenFire
          wrote on 3 Jun 2013, 21:20 last edited by
          #4

          @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);@
          
          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