JSON format support for Qsettings

Source: Internet
Author: User

Always feel that it is convenient to save configuration information with qsettings, in order to make the program more convenient to interact with Web programs and databases such as Mongodb,redis,postgresql, to add JSON format support for Qsettings

Source code Example:

Https://github.com/tsuibin/Json_format_for_QSettings/blob/master/main.cpp

#include  <QApplication> #include  <QJsonDocument> #include  <QDebug> #include  <QVariant> #include  <qsettings>bool readjsonfile (qiodevice &device,  QSETTINGS::SETTINGSMAP&NBSP;&AMP;MAP) {bool ret = false; Qjsonparseerror error;map = qjsondocument::fromjson (Device.readall ()  , &error). Tovariant (). Tomap (); if ( error.error == QJsonParseError::NoError ) ret = true; Return ret;} Bool writejsonfile (Qiodevice &device, const qsettings::settingsmap &map) {     bool ret = false; Qjsondocument jsondocument = qjsondocument::fromvariant (Qvariant::fromvalue (map));if  (  device.write (Jsondocument.tojson ())  != -1 ) Ret = true;return ret;} Int main (int argc, char *argv[]) {qcoreapplication a (ARGC,&NBSP;ARGV);const  Qsettings:: Format jsonformat = qsettings::registerformat ("JSON",  readjsonfile, writejsonfile); Qsettings settings (jsonformat, qsettings::userscope,  "JSON", "Cazool"); Qmap<qstring, qvariant> cazooldata;cazooldata.insert ("Address", "China"); Cazooldata.insert ("The Age Cazooldata.insert ("Tel", "13888888888"), Settings.remove ("Tsuibin"); Settings.setvalue ("Cazool",  Qvariant::fromvalue (Cazooldata)); Return a.exec ();}


JSON format support for Qsettings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.