Qt4第三方库QJSON编译说明

来源:互联网 发布:服装设计绘图软件 编辑:程序博客网 时间:2024/05/16 14:08


1. 下载QJSON源文件压缩包qjson-0.8.1.tar.bz2

2. Qt Create上使用cmake命令编译QJSON

(a) Qt Create中打开QJSON源文件中的CMakeLists.txt文件。

(b) 弹出Run CMake设置界面,点击界面上的Run CMake检测通过,然后点击Finish按钮完成cmake环境配置。

(c) 最后执行build命令编译源文件,会在lib目录下生成qjson.libqjson.dll文件,编译完成。

 

3. 使用QJSON例程

#include <QCoreApplication>

#include <QVariantMap>

#include <QDebug>

#include "./src/parser.h"

 

int main(int argc, char *argv[])

{

         QCoreApplication app(argc, argv);

        QString json("{"

                "\"encoding\" : \"UTF-8\","

                "\"plug-ins\" : ["

                "\"python\","

                "\"c++\","

                "\"ruby\""

                "],"

                "\"indent\" : { \"length\" : 3, \"use_space\" : true }"

        "}");

 

      QJson::Parser parser;

      bool ok;

     QVariantMap result = parser.parse (json.toAscii(), &ok).toMap();

     if (!ok) {

         qFatal("An error occurred during parsing");

           exit (1);

      }

 

      qDebug() << "encoding:" << result["encoding"].toString();

      qDebug() << "plugins:";

      foreach (QVariant plugin, result["plug-ins"].toList()) {

            qDebug() << "\t-" << plugin.toString();

      }

      QVariantMap nestedMap = result["indent"].toMap();

      qDebug() << "length:" << nestedMap["length"].toInt();

      qDebug() << "use_space:" << nestedMap["use_space"].toBool();

      return app.exec();

}


1 0
原创粉丝点击