//配置应答--检测点设置写文件
if(p9==0x03){
//需要注意:json对象中的[]应转成JsonArray,{}应转成JsonObject,p10是json字符串
QJsonDocument jsonDocument = QJsonDocument::fromJson(p10);//从传入的json字符串中生成一个json文件
QJsonObject convertedJsonObject = jsonDocument.object();//从json文件中转成json对象
QJsonArray p_Object = convertedJsonObject["pointsArray"].toArray();//从json对象中取到jsonArray
for(int i=1;i<=SUPPORTED_MAX_POINTS_PERCAMERA;i++){
paramsPoint point;//根据接收的修改后的配置文件创建一个类并更新
QJsonObject p_sub_Object = p_Object.at(i-1).toObject();
point.setX(p_sub_Object["x"].toInt());//设置主检测点坐标x
point.setY(p_sub_Object["y"].toInt());//设置主检测点坐标y
point.setName(p_sub_Object["name"].toString());//设置检测点名称
point.setValid(p_sub_Object["valid"].toInt());//设置主检测点是否有效
point.setSubValid(p_sub_Object["subvalid"].toInt());//设置辅检测点是否有效
// 获取subpoint对象
paramsSubPoint params_sub_point;
QJsonObject sub_point_Object = p_sub_Object["subpoint"].toObject();
params_sub_point.setX(sub_point_Object["x"].toInt());
params_sub_point.setY(sub_point_Object["y"].toInt());
point.setSubpoint(params_sub_point);//设置辅检测点:subpoint
// 获取Channel4U对象
params4UDirection params_chnnel_4u;
QJsonObject chnnel_4u_Object = p_sub_Object["channel4U"].toObject();
params_chnnel_4u.setChannel(chnnel_4u_Object["channel"].toInt());
params_chnnel_4u.setDirection(chnnel_4u_Object["direction"].toInt());
point.setChannel4U(params_chnnel_4u);//设置4U通道:Channel4U
point.setChannelNo(p_sub_Object["channelNo"].toInt());//设置通道号
// 获取PointType对象
paramsChannelType params_PointType;
QJsonObject ChannelType_Object = p_sub_Object["pointtype"].toObject();
params_PointType.setGoChannel(p_sub_Object["go"].toInt(),p_sub_Object["goEN"].toInt());
params_PointType.setLeftChannel(p_sub_Object["left"].toInt(),p_sub_Object["leftEN"].toInt());
params_PointType.setLeftChannel(p_sub_Object["right"].toInt(),p_sub_Object["rightEN"].toInt());
point.setPointtype(params_PointType);//设置检测点类型:pointType
point.setRedLightX(p_sub_Object["redlightx"].toInt());//红灯坐标x
point.setRedLightY(p_sub_Object["redlighty"].toInt());//红灯坐标y
point.setSpecValid(p_sub_Object["specvalid"].toInt());//帧差轮廓专用点是否有效
paramsSpecPoint params_spec_point;
QJsonObject spec_point_Object = p_sub_Object["specpoint"].toObject();
params_spec_point.setX(spec_point_Object["x"].toInt());
params_spec_point.setX(spec_point_Object["y"].toInt());
point.setSpecpoint(params_spec_point);//设置专用点坐标:spec_point
point.setQueueValid(p_sub_Object["queue"].toInt());//设置是否计算排队长度
point.setCheckmethod(p_sub_Object["checkmethod"].toInt());//设置检车算法
point.setGreenLightX(p_sub_Object["greenlightx"].toInt());//设置绿灯坐标x
point.setGreenLightY(p_sub_Object["greenlighty"].toInt());//设置绿灯坐标y
point.setGreenLessInterval(p_sub_Object["greenLessInterval"].toInt());//设置绿损间隔
gCarDetectorParams.configParams.getCamera(camId)->setPoint(i,point);//依次更新各检测点的参数
}
gCarDetectorParams.saveparam();//最后更新配置文件
}
UDP端口接收到的字节流如何转为QJsonObject、QJsonArray的方法
于 2023-11-21 14:15:41 首次发布