本文整理汇总了C++中JsonDataAccess::error方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonDataAccess::error方法的具体用法?C++ JsonDataAccess::error怎么用?C++ JsonDataAccess::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonDataAccess
的用法示例。
在下文中一共展示了JsonDataAccess::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool LoginReply::parse(const QByteArray& data)
{
JsonDataAccess jsonObject;
QVariant node = jsonObject.loadFromBuffer(data);
if (jsonObject.hasError()) {
qWarning() << "error converting JSON data: " << jsonObject.error().errorMessage();
} else {
qDebug() << "before parse: " << QString(data);
QVariantMap map = node.value<QVariantMap>();
if (map["status"].toString() == "OK") {
m_status = true;
m_sessionKey = map["sessionKey"].toString();
QVariantList friendList = map["friends"].value<QVariantList>();
for (int i = 0; i < friendList.size(); i++) {
m_ppIds.append(friendList[i].toString());
}
QVariantList pinList = map["pins"].value<QVariantList>();
for (int i = 0; i < pinList.size(); i++) {
m_pins.append(pinList[i].toString());
}
return true;
}
}
return false;
}
示例2: onRequestUsers
void QBNetwork::onRequestUsers() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
QString response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
emit usersReceived(response);
}
} else {
emit error("Wrong reply for request users request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for request users request");
}
disconnectFromAll();
}
示例3: parse
bool GetLocationsReply::parse(const QByteArray& data)
{
JsonDataAccess jsonObject;
QVariant node = jsonObject.loadFromBuffer(data);
if (jsonObject.hasError()) {
qWarning() << "error converting JSON data: " << jsonObject.error().errorMessage();
} else {
qDebug() << "before parse: " << QString(data);
QVariantMap map = node.value<QVariantMap>();
if (map["status"].toString() == "OK") {
m_status = true;
QVariantList friendList = map["friends"].value<QVariantList>();
for (int i = 0; i < friendList.size(); i++) {
QString friendStr = friendList[i].toString();
QStringList fields = friendStr.split(",");
// if incorrect number of fields, stop parsing
if (fields.size() != 4) return false;
QString ppId = fields.at(0);
double x = fields.at(1).toDouble();
double y = fields.at(2).toDouble();
int visibility = fields.at(3).toInt();
m_friends.append(User(ppId, x, y, visibility));
}
return true;
}
}
return false;
}
示例4: onRequestSessionRegister
void QBNetwork::onRequestSessionRegister() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "session") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "user_id") {
m_userId = sit.value().toString();
}
if (sit.key() == "token") {
m_token = sit.value().toString();
}
}
}
}
if (m_token != NULL) {
//register after we have session
emit sessionEstablished();
registerNewUser();
} else {
emit error("Wrong reply for register session request");
}
}
} else {
emit error("Wrong reply for register session request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for register session request");
}
disconnectFromAll();
}
示例5: startLevel
void ApplicationUI::startLevel(const QVariantList &indexPath)
{
if (!m_gamePage) {
QmlDocument *qml = QmlDocument::create("asset:///Game.qml").parent(this);
qml->setContextProperty("_app", this);
m_gamePage = qml->createRootObject<Page>();
m_progressAnimation = m_gamePage->findChild<SequentialAnimation*>("progressAnimation");
}
if (indexPath.count() > 0)
m_levelIndex = indexPath[0].toInt();
else
m_levelIndex = 0; // Uhoh?
m_phase = COMPILE;
m_selectedFunction = 0;
setShouldShowFunctions(false);
setIsInFunction(-1);
Container *compileContainer = m_gamePage->findChild<Container*>("compilePhaseContainer");
compileContainer->setVisible(true);
m_gamePage->findChild<Container*>("tutorial1Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("tutorial2Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("tutorial3Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("progressBar")->setTranslationX(0);
m_gamePage->findChild<Container*>("creditsContainer")->setVisible(false);
m_gamePage->findChild<Button*>("menuButton")->setText("Continue");
m_gamePage->findChild<Container*>("menuContainer")->setVisible(false);
QVariantMap levelInfo = m_levelList->dataModel()->data(indexPath).toMap();
QString levelPath = levelInfo["level"].toString();
JsonDataAccess jda;
qDebug() << "Attempting to load " << levelPath;
QVariantMap levelData = jda.load(levelPath).toMap();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qFatal("JSON loading error: %d: %s", error.errorType(), qPrintable(error.errorMessage()));
return;
} else {
qDebug() << "JSON data loaded OK!";
}
setupLevel(levelData);
setupQueue();
m_navigationPane->push(m_gamePage);
m_timer.setInterval(2000);
m_gamePage->findChild<Container*>("compileFunctionContainer")->setVisible(m_functionCount > 0);
drawSelectedFunction();
}
示例6: onRequestLogin
void QBNetwork::onRequestLogin() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
showError(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "user") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "id") {
break;
}
}
}
}
}
}
} else {
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
response =
tr("Error: %1 status: %2").arg(reply->errorString(),
reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString());
}
reply->deleteLater();
}
requestUsers();
}
示例7: convertQtToJson
//! [2]
void App::convertQtToJson()
{
const QString result = tr("Converting ... ");
setResult(result);
setRhsTitleAndText(mRhsDefaultTitle, "");
QString jsonBuffer;
JsonDataAccess jda;
jda.saveToBuffer(mQtData, &jsonBuffer);
if (jda.hasError()) {
const DataAccessError err = jda.error();
const QString errorMsg = tr("Error converting Qt data to JSON: %1").arg(err.errorMessage());
setResultAndState(errorMsg, QtDisplayed);
} else {
setRhsTitleAndText(tr("JSON Data from Qt"), jsonBuffer);
setResultAndState(result + tr("Success"), ReadyToWrite);
}
}
示例8: setupAlbumListModel
QVariant SongsDataModel::setupAlbumListModel()
{
// Create a new GroupDataModel; the GroupDataModel is a helper class that ListView uses for data handling.
// It uses in-memory storage so we can populate data.
// We load the GroupDataModel with help from the JsonDataAcces function, load().
JsonDataAccess jda;
QDir home = QDir::home();
QVariantMap existingAlbums = jda.load(home.absoluteFilePath("albumslist.json")).value<QVariantMap>();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
return QVariant();
}
// Sort on region in the model so we will get different categories.
//m_albumsModel->insertList(existingAlbums);
return existingAlbums;
}
示例9: convertJsonToQt
//! [1]
void App::convertJsonToQt()
{
const QString result = tr("Converting ... ");
setResult(result);
setRhsTitleAndText(mRhsDefaultTitle, "");
setQtData (QVariant());
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(mJsonData);
if (jda.hasError()) {
const DataAccessError err = jda.error();
const QString errorMsg = tr("Error converting JSON data: %1").arg(err.errorMessage());
setResultAndState(errorMsg, JsonLoaded);
} else {
setQtData(qtData);
const QtObjectFormatter fmt;
setRhsTitleAndText(tr("Qt Data from JSON"), fmt.asString(qtData));
setResultAndState(result + tr("Success"), QtDisplayed);
}
}
示例10: load
void MyListModel::load(const QString& file_name)
{
// clear model
clear();
// clear not filtered data cache
m_data.clear();
{
JsonDataAccess jda;
m_data = jda.load(file_name).toList();
if (jda.hasError()) {
DataAccessError error = jda.error();
qDebug() << file_name << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
}
else {
qDebug() << file_name << "JSON data loaded OK!";
// when loaded, show all data (no filtering)
append(m_data);
}
}
}
示例11: onRegistrationNewUser
void QBNetwork::onRegistrationNewUser() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
QString response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
QVariantMap userDetails = qtData.toMap()["user"].toMap();
if (userDetails.contains("id")) {
m_userId = userDetails["id"].toString();
}
}
if (m_token != NULL && m_userId != NULL) {
emit registered();
// requestLogin();
}
} else {
emit error("Wrong reply for register new user request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for register new user request");
}
disconnectFromAll();
}
示例12: updateThreadsView
void HistoryBrowserController::updateThreadsView(const QByteArray& buffer) {
using namespace bb::data;
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(buffer);
if(jda.hasError()) {
qDebug() << jda.error().errorMessage();
}
if(m_HistoryList == NULL) {
qWarning() << "did not received the list. quit.";
return;
}
using namespace bb::cascades;
GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_HistoryList->dataModel());
dataModel->clear();
dataModel->insertList(qtData.toMap()["threads"].toList());
emit completed();
}
示例13: updateThread
void HistoryBrowserController::updateThread(const QByteArray& buffer) {
using namespace bb::data;
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(buffer);
if(jda.hasError()) {
qDebug() << jda.error().errorMessage();
}
if(m_WebView == NULL) {
qWarning() << "did not received the webview. quit.";
return;
}
QSettings settings("Amonchakai", "Hg10");
QFile htmlTemplateFile(QDir::currentPath() + "/app/native/assets/template.html");
if(bb::cascades::Application::instance()->themeSupport()->theme()->colorTheme()->style() == bb::cascades::VisualStyle::Dark) {
htmlTemplateFile.setFileName(QDir::currentPath() + "/app/native/assets/template_black.html");
}
QFile htmlEndTemplateFile(QDir::currentPath() + "/app/native/assets/template_end.html");
QString ownAvatar = ConversationManager::get()->getAvatar();
if(ownAvatar.mid(0,9).toLower() == "asset:///")
ownAvatar = QDir::currentPath() + "/app/native/assets/" + ownAvatar.mid(9);
// -----------------------------------------------------------------------------------------------
// customize template
if (htmlTemplateFile.open(QIODevice::ReadOnly) && htmlEndTemplateFile.open(QIODevice::ReadOnly)) {
QString htmlTemplate = htmlTemplateFile.readAll();
QString endTemplate = htmlEndTemplateFile.readAll();
// -----------------------------------------------------------------------------------------------
// adjust font size
if(settings.value("fontSize", 28).value<int>() != 28) {
htmlTemplate.replace("font-size: 28px;", "font-size: " + QString::number(settings.value("fontSize").value<int>()) + "px;");
}
// -----------------------------------------------------------------------------------------------
// choose background image
{
QString directory = QDir::homePath() + QLatin1String("/ApplicationData/Customization");
QString filename;
if(QFile::exists(directory + "/" + ConversationManager::get()->getAdressee() + ".xml")) {
filename = directory + "/" + ConversationManager::get()->getAdressee() + ".xml";
} else {
if(QFile::exists(directory +"/default.xml")) {
filename = directory + "/default.xml";
}
}
filename.replace(".xml", ".css");
if(QFile::exists(filename)) {
QFile file(filename);
if (file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
QString themeSettings = stream.readAll();
file.close();
QString suffix;
if(bb::cascades::Application::instance()->themeSupport()->theme()->colorTheme()->style() == bb::cascades::VisualStyle::Dark) {
suffix = "_black";
}
htmlTemplate.replace("</style><link rel=\"stylesheet\" href=\"bubble" + suffix + ".css\">", themeSettings + "\n\r</style>");
}
}
}
// -----------------------------------------------------------------------------------------------
// preload history
QVariantList list = qtData.toMap()["messages"].toList();
bool fistInsertDone = false;
QString body;
QString prevFrom;
for(int i = 0 ; i < list.size() ; ++i) {
QVariantMap map = list.at(i).toMap();
QVariantList headers = map["payload"].toMap()["headers"].toList();
QString contact;
if(!headers.isEmpty())
contact = headers.at(0).toMap()["value"].toString();
QString from;
QString dstName;
QRegExp fromRegExp("(.*) <(.*)>");
if(fromRegExp.indexIn(contact) != -1) {
from = fromRegExp.cap(2);
//.........这里部分代码省略.........
示例14: onRequestSessionWithLogin
void QBNetwork::onRequestSessionWithLogin() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
successShow = true;
emit unauthorizedChanged();
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
showError(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "session") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "user_id") {
m_userId = sit.value().toString();
} else if (sit.key() == "token") {
m_token = sit.value().toString();
}
}
}
}
}
if (m_token != NULL && m_userId != NULL) {
requestLogin();
}
}
} else {
successShow = false;
successLoad = true;
emit unauthorizedChanged();
emit loadingChanged();
emit completeLogin();
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
response =
tr("Error: %1 status: %2").arg(reply->errorString(),
reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString());
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()
== "401") {
showError("Incorrect login or password");
return;
} else if (reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString()
== "422") {
showError("User is not registered 1");
return;
} else if (reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString()
== "404") {
showError("The requested resource could not be found");
return;
} else {
//another error
showError("QBlox Server Error = " + response);
return;
}
}
reply->deleteLater();
}
/* successLoad = true;
emit loadingChanged();
emit completeLogin();*/
}
示例15: onRequestSessionRegister
//SLOTS
void QBNetwork::onRequestSessionRegister() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
QFile sourceFile("app/native/assets/JDataSession.json");
if (!sourceFile.open(QIODevice::WriteOnly))
return;
sourceFile.write(response.toAscii());
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
showError(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "session") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "user_id") {
m_userId = sit.value().toString();
}
if (sit.key() == "token") {
m_token = sit.value().toString();
}
}
}
}
}
}
} else {
successLoad = true;
emit loadingChanged();
emit unauthorizedChanged();
emit completeLogin();
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()
== "401") {
showError("Incorrect login or password");
return;
} else if (reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString()
== "422") {
showError("Login has already been taken");
return;
} else if (reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString()
== "404") {
showError("The requested resource could not be found");
return;
} else {
//another error
showError("QBlox Server Error = " + response);
return;
}
}
reply->deleteLater();
}
//successLoad = true;
//emit loadingChanged();
//emit unauthorizedChanged();
//emit completeLogin();
registrationNewUser();
}