bool JsonTranslator::read_file() { QFile loadFile("../json_test.json"); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open file."); return false; } QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData) ); QJsonObject root = loadDoc.object(); QMessageBox msgbox; QString simple = root["simpleString"].toString(); msgbox.setText(simple); msgbox.exec(); // read listOfVotelists QJsonArray jListOfVotelists = root["listOfVotelists"].toArray(); for (int listIndex = 0; listIndex < jListOfVotelists.size(); ++listIndex) { QJsonArray jVotelist = jListOfVotelists[listIndex].toArray(); std::list<QString> votelist; for (int voteIndex = 0; voteIndex < jVotelist.size(); ++voteIndex) { QString vote = jVotelist[voteIndex].toString(); votelist.push_back(vote); } this->listOfVotelists.push_back(votelist); } // read listOfCoursesAndMaxMembers QJsonArray jListOfCoursesAndMaxMembers = root["listOfCoursesAndMaxMembers"].toArray(); for (int listIndex = 0; listIndex < jListOfCoursesAndMaxMembers.size(); ++listIndex) { QJsonObject jCourse = jListOfCoursesAndMaxMembers[listIndex].toObject(); QString courseName = jCourse.keys()[0]; unsigned maxMembers = jCourse.value(courseName).toInt(); std::tuple<QString, unsigned> course (courseName, maxMembers); this->listOfCoursesAndMaxMembers.push_back(course); } return true; }
bool IndigoMenuBar::loadSettings() { QFile loadFile(QStringLiteral("data/navigation.json")); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open menubarfile."); return false; } QByteArray data = loadFile.readAll(); qDebug() << "data" << data << endl; QJsonParseError jerror; QJsonDocument loadDoc(QJsonDocument::fromJson(data, &jerror)); if(jerror.error != QJsonParseError::NoError) { qWarning("Error while parsing json."); qDebug() << jerror.errorString() << endl; qDebug() << "error at" << QTextCodec::codecForMib(106)->toUnicode(data).mid(jerror.offset - 1, 20) << endl; return false; } read(loadDoc.object()); return true; }
void HTTPWSTest::testLoad() { const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); loadDoc(documentURL); Util::removeFile(documentPath); }
bool FieldsModel::readOffLineFields() { QFile wntlist(FIELDS_FILENAME); if (wntlist.exists()) //Если есть файл с данными, читаем из него { if(!wntlist.open(QIODevice::ReadOnly)) { qDebug() << "Couldn`t open fieldsfile "; return false; } else { QByteArray saveData = wntlist.readAll(); wntlist.close(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData)); QJsonArray result = loadDoc.array(); qDebug() << "Releases in Json " <<result; if (result.size()>0) { emit beginInsertRows(QModelIndex(), rowCount(), rowCount()+result.size()-1); for (QJsonArray::const_iterator iter = result.begin();iter!= result.end(); ++iter) { const QJsonObject o = (*iter).toObject(); QJsonArray options = o["options"].toArray(); QStringList i_options; for (int i=0; i<options.size();i++) { i_options << options.at(i).toString(); } bool i_isDropdown; if (o["type"].toString()=="dropdown") i_isDropdown = true; else i_isDropdown = false; m_Fields << Fields(o["name"].toString(), i_options, o["id"].toInt(), o["position"].toInt(), o["type"].toString(), o["public"].toBool(), o["lines"].toInt(), i_isDropdown); } emit endInsertRows(); } O1Requestor::instance().setIsOffline(true); // Признак того что работаем в оффлайне emit isOfflineChanged(); return true; } } return false; }
void UiThemeSetting::loadUiThemesFromXml(const std::string &xmlfile,UiThemeMgr *mgr) { #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) xmlDocPtr doc = xmlReadFile(xmlfile.c_str(),"utf-8",XML_PARSE_RECOVER); #else unsigned long size = 0; unsigned char *buf = CCFileUtils::sharedFileUtils()->getFileData(xmlfile.c_str(),"r",&size); xmlDocPtr doc = xmlReadMemory((const char*)buf,size,xmlfile.c_str(),NULL,0); #endif loadDoc(doc,mgr); }
CardModel::CardModel() { QFile loadFile(filePath); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open %s file.", filePath.toUtf8().constData()); } QByteArray cardData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(cardData)); assert(loadDoc.isObject()); _object = loadDoc.object(); qDebug() << "card: " << cardId() << ", PIN: " << pinNumString() << '\n'; }
bool LoginManager::load() { QFile loadFile(dataPath + "/cred.dat"); if (!loadFile.open(QIODevice::ReadOnly)) return false; QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromBinaryData(saveData)); QJsonObject saveObject = loadDoc.object(); _accessToken = saveObject["accessToken"].toString(); _refreshToken = saveObject["refreshToken"].toString(); loadFile.close(); return true; }
void initWindow::cargar() { QFile loadFile(QStringLiteral("save.json")); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open save file."); return ; } QByteArray datos = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(datos)); read(loadDoc.object()); }
bool Config::load() { qDebug() << "Loading config file:" << m_filename; QFile file(m_filename); if (!file.open(QIODevice::ReadOnly)) return false; QJsonDocument loadDoc(QJsonDocument::fromJson(file.readAll())); m_data = loadDoc.object(); file.close(); return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //Coloca m_Widgets[ WidgetID::TempoTotal ] << ui->labelTempoTotal; m_Widgets[ WidgetID::TempoTotal ] << ui->lineEditTempoTotal; m_Widgets[ WidgetID::Dte ] << ui->labelDte; m_Widgets[ WidgetID::Dte ] << ui->lineEditDte; m_Widgets[ WidgetID::Densidade ] << ui->labelDensidade; m_Widgets[ WidgetID::Densidade ] << ui->lineEditDensidade; QFile inputFile("widgets.json"); if (!inputFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open widgets file."); return; } QByteArray saveData = inputFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData)); QJsonObject jsonObj = loadDoc.object(); QJsonArray widgetsArray = jsonObj["widgets"].toArray(); for (int levelIndex = 0; levelIndex < widgetsArray.size(); ++levelIndex) { QJsonObject widget = widgetsArray[levelIndex].toObject(); qDebug() << widget["id"].toInt(); qDebug() << widget["name"].toString(); qDebug() << widget["visible"].toBool(); this->setHidden(widget["id"].toInt(), !widget["visible"].toBool()); } // this->setHidden(WidgetID::TempoTotal, true); // this->setHidden(WidgetID::Dte, false); // this->setHidden(WidgetID::Densidade, true); }
void MetaDataWriter::load(Closet &clst) { m_closet = &clst; QFile loadFile(m_filename); QJsonObject top; if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("dressr.json could not be opened for reading!"); return; } QByteArray loadData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(loadData)); top = loadDoc.object(); clst.read(top["Closet"].toObject()); }
bool JsonFileReader::read(const std::string &fileDir) { QFile loadFile(QString::fromUtf8(fileDir.c_str())); if (!loadFile.open(QIODevice::ReadOnly)) { return false; } QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData)); QJsonObject jsonObj = loadDoc.object(); QJsonArray canvasShapes = jsonObj["CanvasShapes"].toArray(); readGroup(m_mainGroup, canvasShapes); return true; }
//! [3] bool Game::loadGame(Game::SaveFormat saveFormat) { QFile loadFile(saveFormat == Json ? QStringLiteral("save.json") : QStringLiteral("save.dat")); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open save file."); return false; } QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc(saveFormat == Json ? QJsonDocument::fromJson(saveData) : QJsonDocument::fromBinaryData(saveData)); read(loadDoc.object()); return true; }
///******************************************************************************************* bool WantlistModel::readOffLineWantList() { QFile wntlist(WANTLIST_FILENAME); if (wntlist.exists()) //Если есть файл с данными, читаем из него { if(!wntlist.open(QIODevice::ReadOnly)) { qDebug() << "Couldn`t open wantlistfile "; return false; } else { QByteArray saveData = wntlist.readAll(); wntlist.close(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData)); QJsonArray result = loadDoc.array(); qDebug() << "Releases in Json " <<result; if (result.size()>0) { emit beginInsertRows(QModelIndex(), rowCount(), rowCount()+result.size()-1); for (QJsonArray::const_iterator iter = result.begin();iter!= result.end(); ++iter) { const QJsonObject o = (*iter).toObject(); // qDebug() << "Release " << o; addResult (o); } emit endInsertRows(); } O1Requestor::instance().setIsOffline(true); // Признак того что работаем в оффлайне emit isOfflineChanged(); return true; } } return false; }
bool Ingridients::loadData(QString& fileName) { QFile loadFile(fileName); PRINT_DEBUG("Loading new ingridients"); if ( !loadFile.open(QIODevice::ReadOnly) ) { PRINT_WARN("Couldn't open save file."); return false; } QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc((!fileName.right(5).compare(".json")) ? QJsonDocument::fromJson(saveData) : QJsonDocument::fromBinaryData(saveData)); loadDish(loadDoc.object()["dishList"].toArray()); loadFood(loadDoc.object()["foodList"].toArray()); loadItems(loadDoc.object()["itemList"].toArray()); return true; }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_STENCIL); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keypress); try { svgl::InitHelper * initHelper = svgl::InitHelper::get(); displayManager = initHelper->displayManager; const char * filename = ""; if(argc==2) { filename = argv[1]; } thesvgdoc = loadDoc(filename); if(thesvgdoc) glutMainLoop(); } catch (dom::DOMException& e) { std::cerr << e.what() << __FL__; throw; } catch (std::exception& e) { std::cerr << e.what() << __FL__; throw; } catch (...) { std::cerr << "unknown exception" << __FL__; throw; } return 0; }
void UiThemeSetting::loadFromXmlMemory(const char *buffer, int size, UiThemeMgr *mgr) { xmlDocPtr doc = xmlReadMemory(buffer,size,0,"utf-8",XML_PARSE_RECOVER); loadDoc(doc,mgr); }