• Salman_1
    了解作者
  • QT
    开发工具
  • 353KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2020-03-17 00:04
    上传日期
qtrest,qt,c++,rest client
qtrest-master.zip
  • qtrest-master
  • src
  • models
  • abstractxmlrestlistmodel.cpp
    4.9KB
  • pagination.cpp
    3.3KB
  • abstractjsonrestlistmodel.h
    482B
  • detailsmodel.h
    326B
  • detailsmodel.cpp
    770B
  • abstractxmlrestlistmodel.h
    1.4KB
  • baserestlistmodel.cpp
    12.6KB
  • xmlrestlistmodel.cpp
    561B
  • requests.h
    979B
  • jsonrestlistmodel.h
    899B
  • requests.cpp
    82B
  • baserestlistmodel.h
    6.9KB
  • xmlrestlistmodel.h
    846B
  • jsonrestlistmodel.cpp
    618B
  • abstractjsonrestlistmodel.cpp
    1.1KB
  • restitem.h
    501B
  • pagination.h
    4.1KB
  • restitem.cpp
    891B
  • usingleton.h
    887B
  • apibase.h
    4.5KB
  • apibase.cpp
    8.1KB
  • docs
  • restapi.png
    330.5KB
  • QtMicroRestFramework.qmodel
    108.5KB
  • LICENSE
    1.1KB
  • com_github_kafeg_qtrest.qbs
    1.2KB
  • com_github_kafeg_qtrest.pri
    1KB
  • .gitignore
    301B
  • README.md
    15.4KB
  • qmldir
    32B
  • com_github_kafeg_qtrest.qrc
    109B
  • qpm.json
    541B
内容介绍
# Qt / QML REST Client (Beta) **NOTE: the last changes break the compatibility with the previous versions of the library. See the `expand` parameter.** Qt REST Client - small and simple REST API client for any Qt/QML application. Library support standard JSON and XML REST APIs and auto mapping REST data to QAbstractListModel for QML Manual in russian: https://habrahabr.ru/post/314984 By default library support standard Yii2 REST API and Django REST Framework. Read more: - English: https://github.com/yiisoft/yii2/blob/master/docs/guide/rest-quick-start.md - Russian: https://github.com/yiisoft/yii2/blob/master/docs/guide-ru/rest-quick-start.md - http://www.django-rest-framework.org/ ## Features - Based on QAbstractListModel with fetchMore and canFetchMore support; - Support JSON and XML list data; - Pagination by per page, limit/offset or cursor; - Sorting data; - Filtering data; - Authentication; - StackView navigation; - Specify fields for GET list method; - Specify expand parameter for GET list method to expand relational data; - Lazy loading details item data; - Separate model and API methods; - Simple API implementation for your apps; - State based model information; - Requires ID field for each record; - Interfaces from C++ and Qt Quick/QML; - Multiple external API services in different models; - Predefined or custom model classes ![Qt Micro REST Client Framework](https://raw.githubusercontent.com/kafeg/qtrest/master/docs/restapi.png "REST API Scheme") ## Known issues/TODO - No cache for data; - Support JSON subarray data, but not support XML subarray data; ## Example application I will made fully functionality example application, available at here: https://github.com/kafeg/qtrest-example ## Usage Usage library is simplest as it possible. I will show howto use it on my real example project. #### 1. Include library to your project First, clone library. ``` mkdir PROJECT_ROOT/api/ cd PROJECT_ROOT/api/ git clone https://github.com/kafeg/qtrest.git ``` If you're using qmake, just add `include (api/qtrest/com_github_qtrest.pri)` to the .pro file. For Qbs, please make the following adjustments inside the .qbs file: ``` import qbs Project { ... references: "qtrest/com_github_kafeg_qtrest.qbs" Product { ... Depends { name: "qtrest" } ... } } ``` #### 2. Create your own API class After setup library we must create class API inherited from existing APIBase, e.g. `api/api.h` and `api/api.cpp`: ``` C++ #ifndef SKIDKZAPI_H #define SKIDKZAPI_H #include "apibase.h" #include <QtQml> class SkidKZApi : public APIBase { Q_OBJECT public: Q_INVOKABLE explicit SkidKZApi(); //register API object in QML static void declareQML() { qmlRegisterType<SkidKZApi>("com.github.qtrestexample.skidkzapi", 1, 0, "SkidKZApi"); } //handle all requests from ReadOnly model QNetworkReply *handleRequest(QString path, QStringList sort, Pagination *pagination, QVariantMap filters = QVariantMap(), QStringList fields = QStringList(), QStringList expand = QStringList(), QString id = 0); //Method API /v1/coupon QNetworkReply *getCoupons(QStringList sort, Pagination *pagination, QVariantMap filters = QVariantMap(), QStringList fields = QStringList(), QStringList expand = QStringList()); //Method API /v1/coupon/{id} QNetworkReply *getCouponDetail(QString id); //Method API /v1/categories QNetworkReply *getCategories(QStringList sort, Pagination *pagination); }; #endif // SKIDKZAPI_H ``` And implement this class: ``` C++ #include "skidkzapi.h" #include <QFile> #include <QTextStream> #include <QUrlQuery> SkidKZApi::SkidKZApi() : APIBase(0) { } QNetworkReply *SkidKZApi::handleRequest(QString path, QStringList sort, Pagination *pagination, QVariantMap filters, QStringList fields, QStringList expand, QString id) { if (path == "/v1/coupon") { return getCoupons(sort, pagination, filters, fields, expand); } else if (path == "/v1/coupon/{id}") { return getCouponDetail(id); } else if (path == "/v1/categories") { return getCategories(sort, pagination); } } QNetworkReply *SkidKZApi::getCoupons(QStringList sort, Pagination *pagination, QVariantMap filters, QStringList fields, QStringList expand) { QUrl url = QUrl(baseUrl()+"/v1/coupon"); QUrlQuery query; //Sorting if (!sort.isEmpty()) { query.addQueryItem("sort", sort.join(",")); } //Paging switch(pagination->policy()) { case Pagination::PageNumber: query.addQueryItem("per-page", QString::number(pagination->perPage())); query.addQueryItem("page", QString::number(pagination->currentPage())); break; case Pagination::None: case Pagination::Infinity: case Pagination::LimitOffset: case Pagination::Cursor: default: break; } //Filter if (!filters.isEmpty()) { QMapIterator<QString, QVariant> i(filters); while (i.hasNext()) { i.next(); query.addQueryItem(i.key(), i.value().toString()); } } //Only needed fields if (!fields.isEmpty()) { query.addQueryItem("fields", fields.join(",")); } //Additional fields to expand relational data if (!expand.isEmpty()) { query.addQueryItem("expand", expand.join(",")); } //Make query url.setQuery(query.query()); //Make GET request QNetworkReply *reply = get(url); return reply; } QNetworkReply *SkidKZApi::getCouponDetail(QString id) { if (id.isEmpty()) { qDebug() << "ID is empty!"; return 0; } QUrl url = QUrl(baseUrl()+"/v1/coupon/"+id); QNetworkReply *reply = get(url); return reply; } QNetworkReply *SkidKZApi::getCategories(QStringList sort, Pagination *pagination) { QUrl url = QUrl(baseUrl()+"/v1/categories"); QUrlQuery query; if (!sort.isEmpty()) { query.addQueryItem("sort", sort.join(",")); } switch(pagination->policy()) { case Pagination::PageNumber: query.addQueryItem("per-page", QString::number(pagination->perPage())); query.addQueryItem("page", QString::number(pagination->currentPage())); break; case Pagination::None: case Pagination::Infinity: case Pagination::LimitOffset: case Pagination::Cursor: default: break; } url.setQuery(query.query()); QNetworkReply *reply = get(url); return reply; } ``` #### 3. Create your model classes or use completed components, based on your API ##### 3.1 Completed components For simple readonly models you may use complete QML data components called JsonRestListModel {} and XmlRestListModel {}. You hasn't access to manipulate data in this models and pre process items, but by using it you may to skip defining custom C++ models. For example, start in your QML code: ``` ... SkidKZApi { id: skidKZApi ... } JsonRestListModel { id: jsonCouponsModel api: skidKZApi idField: 'id' requests { get: "/v1/coupon" getDetails: "/v1/coupon/{id}" } filters: {'isArchive': '0'} fields: ['id','title'] expand: ['city'] sort: ['-id'] pagination { policy: Pagination.PageNumber perPage: 20 } Component.onCompleted: { reload(); } } ``` ##### 3.2 Custom models For example we create one model, but you may use one API class for multiple models. E.g. you may use one API class for get list of coupons and for list of categories. At this point you have full control on your rest data. You model class must reimplement 6 methods: ``` - declareQML(); //Declare you model for use it in QML code - fetchMoreImpl(); //Call API fucntion for fetchMore function (e.g. getCoupons()) - fetchDetailImpl(); //Call API fucntion for fetchDetails for one item (e.g. getCouponDetail()) - preProcessItem(); //Pre proccess each
评论
    相关推荐
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等
    • 卷积神经网络
      这是卷积神经网络的一个实际用例,已经调试好了,能够在matlab上成功运行,适合从事卷积神经网络(CNN)研究的人员学习使用。
    • android从bootloader到launcher启动流程整理
      讲述android 开机流程 从boot rom---bootloader---init--zygote---systemserver---ams 并附上自己整理的每个流程的流程图 ,清晰熟悉android 启动流程
    • 分数阶混沌系统:分数阶混沌系统的数值解。-matlab开发
      该工具箱包含可用于模拟一些著名的分数阶混沌系统的函数,例如: - 陈的系统, - Arneodo的系统, - Genesio-Tesi 的系统, - 洛伦兹系统, - 牛顿-莱普尼克系统, - 罗斯勒的系统, - Lotka-Volterra系统, - 达芬的系统, - 范德波尔的振荡器, -伏打的系统- 陆氏系统, - 刘的系统, - Chua的系统, - 金融系统, - 3 细胞 CNN。 这些函数以数值方式计算描述混沌系统的分数阶非线性微分方程的解。 每个函数返回总模拟时间的状态轨迹(吸引器)。 更多详情请看书: Ivo Petras,分数阶非线性系统:建模、分析和仿真,Springer,系列:非线性物理科学,2011,ISBN 978-3-642-18100-9。 http://www.springer.com/engineering/control/book/978-3-
    • matlabpam代码-dsp-library:用于光通信的MATLABDSP函数库
      matlab pam代码 DSP库 该项目包含几种不同的功能,可将DSP算法应用于光通信。 这些功能适用于相干和非相干(PAM,DMT)光通信。 大多数功能是相互独立的。 因此,该代码中的功能可以轻松使用,并与其他DSP功能结合使用。 用法 功能列表以及简短说明在文件中。 输入和输出参数的描述在每个函数的标题中。 讯号 通常,输入(和输出)信号在第一维度上具有时间(例如,列向量),而第二维度用于一次管理多个信号(例如,不同的极化,不同的参数等)。 之所以选择这种约定,是因为MATLAB通过将列保留在内存的连续部分中来存储矩阵,因此,这种约定比其他方法(行向量)要快。 参数 大多数功能使用参数结构作为输入参数。 函数中使用的参数的描述通常在标头中,而coherent-dsp函数的默认参数在文件中。 参考 执照 此代码在下发布。
    • 有关多目标跟踪的PHD滤波的一些资料
      一些关于多目标跟踪的新的文献,主要是有关概率假设密度(PHD)的
    • 基于python开发的全国新工商采集工具 v1.2版本
      这个软件是通过scrapy爬虫框架结合代理IP池再加上request模拟请求技术以及验证码识别技术,可以做到日更新采集全国新工商信息。采集的数据自动存储在mysql数据库表里,可下载全量1.8亿多企业工商基本信息和36维度的详细信息.支持sql和excel导出数据包格式。
    • Aerosim Blockset
      The AeroSim aeronautical simulation blockset provides a complete set of tools for the rapid development of nonlinear 6-degree of freedom aircraft dynamic models. In addition to the basic aircraft dynamics blocks, the library also includes complete aircraft models which can be customized through parameter files.
    • matlab匹配滤波代码-matlab_for_thesis:Matlab博士学位论文代码
      matlab匹配滤波代码博士论文的MATLAB代码 博士论文的MATLAB代码的一部分,“井田双色散水下声通道中的多载波通信”。 函数下的func_JingTian文件夹 FUNC_JINGTIAN包含多载波通信中一些通常需要的功能: OFDM调制/解调模块,包括几种数据辅助的信道估计方法和差分解调; 快速实现GFDM和C-FBMC调制/解调,分别包括时域和频域的迫零(ZF)和匹配滤波(MF)均衡; 为OFDM信道估计中使用的压缩感测方法计算字典的功能; 增加信道效应,施加宽带多普勒失真的功能; 通过线性调频Z变换(CZT)以任意精度对频域中的信号进行重采样; Hermite函数合成的信号之间的交叉歧义函数的计算。 演示文件夹 以下列出了四个演示 demo1:使用基本追踪(BP)算法形式的压缩感知方法对OFDM进行稀疏2-D信道估计; demo2:比较基本数据辅助OFDM信道估计算法,包括常规频域插值和基于IDFT的变换域方法; demo3:圆形滤波器组多载波(C-FBMC / OQAM)的基于DFT特征向量的原型滤波器合成; demo4:用于广义频分复用(GFDM)的辅助日期辅助无干