本文整理汇总了C++中qjson::Serializer::errorMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ Serializer::errorMessage方法的具体用法?C++ Serializer::errorMessage怎么用?C++ Serializer::errorMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qjson::Serializer
的用法示例。
在下文中一共展示了Serializer::errorMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recent
Cache::~Cache() {
QString error;
write_file(directory() + "/cache-info", &error, recent().join("\n").toAscii());
if (!error.isEmpty()) {
qFatal("Unable to save cache: %s", qPrintable(error));
}
foreach (QString name, recent()) {
if (!data().contains(name)) continue;
qDebug() << "Saving cached data:" << name;
QVariantMap map = data()[name].toMap();
QString error; bool ok; QJson::Serializer serializer;
write_file(directory() + '/' + name.replace('/', '-'), &error, serializer.serialize(map, &ok));
if (!error.isEmpty()) {
qWarning() << "Error while saving cache: " + error;;
continue;
}
if (!ok) {
error = INVALID_JSON + serializer.errorMessage();
qWarning() << "Error while saving cache: " + error;
continue;
}
}
}
示例2: Serialize
QByteArray Serialize(const QVariant &variant, IndentMode indentMode, bool *ok)
{
QJson::Serializer serializer;
serializer.setIndentMode(static_cast<QJson::IndentMode>(indentMode));
QByteArray data = serializer.serialize(variant, ok);
if (ok != 0 && *ok == false)
LogError(QString("TundraJson::Serialize: %1").arg(serializer.errorMessage()));
return data;
}
示例3: main
int main(int argc, char *argv[]) {
QCoreApplication app (argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForCStrings(codec);
#endif
QTime time;
int duration;
CmdLineParser cmd (app.arguments());
CmdLineParser::Result res = cmd.parse();
if (res == CmdLineParser::Help)
return 0;
else if (res == CmdLineParser::Error)
return -1;
QString filename = cmd.file();
if (!QFile::exists ( filename )) {
qCritical ("The file you specified doesn't exist!");
exit (1);
}
Parser parser;
bool ok;
QFile file (filename);
time.start();
QVariant data = parser.parse (&file, &ok);
duration = time.elapsed();
if (!ok) {
qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
exit (1);
}
else {
qDebug() << "Parsing of" << filename << "took" << duration << "ms";
if (!cmd.quiet())
qDebug() << data;
}
if (cmd.serialize()) {
// serializer tests
qDebug() << "Serializing... ";
QJson::Serializer serializer;
serializer.setIndentMode(cmd.indentationMode());
time.start();
QByteArray b = serializer.serialize(data, &ok);
if (!ok) {
qCritical() << "Serialization failed:" << serializer.errorMessage();
exit(1);
} else {
duration = time.elapsed();
qDebug() << "Serialization took:" << duration << "ms";
if (!cmd.quiet())
qDebug() << b;
}
}
qDebug() << "JOB DONE, BYE";
return 0;
}
示例4: getFlowsFromController
void ShowFlowsDialog::getFlowsFromController()
{
//清空表格
if(ui->flowShowWidget->item(0,0))
{
ui->flowShowWidget->clear();
}
int rowSpanCount = 0, columnSpanCount =1;
int rowbegin = 0;
QString t_flowsStr;
m_curl->getFlows(t_flowsStr);
if(t_flowsStr.isEmpty())
return;
qDebug()<<t_flowsStr;
QJson::Parser parser;
bool ok;
QVariantMap t_flowsMap = parser.parse(t_flowsStr.toUtf8(), &ok).toMap();
if (!ok) {
//qFatal("An error occurred during parsing");
return;
}
qDebug()<< "get flows success!";
//通过交换机的名字获取交换机的流表
for(int i=0; i < m_switchNames.size()/*交换机的数量*/; ++i)
{
qDebug()<< m_switchNames.at(i);
QVariant t_switchFlows = t_flowsMap[m_switchNames.at(i)];
qDebug()<< t_switchFlows;
QVariantList t_switchFlowList = t_switchFlows.toList();
qDebug()<< t_switchFlowList.size();
if(t_switchFlowList.size() <= 0)
continue;
rowSpanCount = t_switchFlowList.size();
QTableWidgetItem *newItem11 = new QTableWidgetItem(m_switchNames.at(i));
newItem11->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
ui->flowShowWidget->setItem(rowbegin, 0, newItem11);
int flowRow = rowbegin;
for(int j=0; j<t_switchFlowList.size()/*交换机中流表数量*/; ++j)
{
QVariantMap t_sFlowMap= t_switchFlowList.at(j).toMap();
//qDebug()<< ttt["switchDPID"].toString();
QJson::Serializer serializer;
bool ok;
QByteArray t_flow = serializer.serialize(t_sFlowMap, &ok);
QString t_flowStr = t_flow;//交换机的一个流表
if (ok) {
qDebug() << t_flowStr;
} else {
qCritical() << "Something went wrong:" << serializer.errorMessage();
}
//获取name
QStringList t_flowStrList = t_flowStr.split(":");
qDebug() << t_flowStrList;
QString t_name;//交换机流表中的名字
if (t_flowStrList.size()>=1)
{
QString t_first = t_flowStrList.at(0);
for (int i = 1; i < t_first.size(); ++i)
{
t_name.append(t_first.at(i));
}
}
qDebug()<<t_name;
QTableWidgetItem *newItem12 = new QTableWidgetItem(t_name);
newItem12->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
ui->flowShowWidget->setItem(flowRow, 1, newItem12);
QTableWidgetItem *newItem13 = new QTableWidgetItem(t_flowStr);
newItem13->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
ui->flowShowWidget->setItem(flowRow, 2, newItem13);
flowRow++;
}
ui->flowShowWidget->setSpan(rowbegin,0,rowSpanCount,1);
rowbegin += rowSpanCount;
}
m_platform->historyListWidget->append(NetworkSimulationPlatform::getSysTime()+tr(": get Flows!"));
}