本文整理汇总了C++中JsonDataAccess::load方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonDataAccess::load方法的具体用法?C++ JsonDataAccess::load怎么用?C++ JsonDataAccess::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonDataAccess
的用法示例。
在下文中一共展示了JsonDataAccess::load方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadConfigFromJson
//load data from json into controllers
//{ "device" : int,
// "buttons": [ int, int, int, ..., 16]
//}
int Frontend::loadConfigFromJson(QString file) {
JsonDataAccess jda;
int i;
QVariantMap data = jda.load(file).toMap();
if(data.isEmpty()){
return -1;
}
m_controllers[0].device = data["device"].toInt();
if(data["buttons"].isValid()){
for(i=0;i<16;++i) {
m_controllers[0].buttons[i] = data["buttons"].toList()[i].toInt();
}
}
if(data["gamepad"].isValid()){
for(i=0;i<16;++i) {
m_controllers[0].gamepad[i] = data["gamepad"].toList()[i].toInt();
}
}
return 0;
}
示例2: removeAccountAt
void AccountList::removeAccountAt(int i)
{
JsonDataAccess jda;
QVariantList list = jda.load(this->file).value<QVariantList>();
list.removeAt(i);
jda.save(QVariant(list), this->file);
loadAccounts();
}
示例3: parseJSON
void RocknRoll::parseJSON() {
GroupDataModel *model = new GroupDataModel(QStringList() << "artist" << "song" << "genre" << "year");
JsonDataAccess jda;
QVariant list = jda.load("dummy.json");
model->insertList(list.value<QVariantList>());
ListView *listView = new ListView();
listView->setDataModel(model);
}
示例4: findCores
void RetroArch::findCores()
{
DIR *dirp;
struct dirent* direntp;
int count=0, i=0;
dirp = opendir(g_settings.libretro);
if( dirp != NULL )
{
for(;;)
{
direntp = readdir( dirp );
if( direntp == NULL ) break;
count++;
}
fflush(stdout);
rewinddir(dirp);
if(count==2)
{
printf("No Cores Found");fflush(stdout);
}
coreList = (char**)malloc(count*sizeof(char*));
count = 0;
for(;;)
{
direntp = readdir( dirp );
if( direntp == NULL ) break;
coreList[count++] = strdup((char*)direntp->d_name);
}
//Load info for Cores
JsonDataAccess jda;
coreInfo = jda.load("app/native/assets/coreInfo.json").toMap();
Option *tmp;
//Populate DropDown
for (i = 2; i < count; ++i)
{
qDebug() << GET_CORE_INFO(i, "display_name");
tmp = Option::create().text(GET_CORE_INFO(i, "display_name"))
.value(i);
coreSelection->add(tmp);
}
}
closedir(dirp);
}
示例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: loadAccounts
void AccountList::loadAccounts()
{
this->accounts = QList<Account>();
JsonDataAccess jda;
QVariantList list = jda.load(this->file).value<QVariantList>();
bool* ok = new bool;
for(int i = 0; i < list.size(); i++)
{
accounts.append(Account(list.at(i).toMap().value("name").toString(), list.at(i).toMap().value("start").toInt(ok), list.at(i).toMap().value("stop").toInt(ok)));
}
delete(ok);
}
示例7: editAccount
void AccountList::editAccount(int i, QString name, int start, int stop)
{
JsonDataAccess jda;
QVariantList list = jda.load(this->file).value<QVariantList>();
QVariantMap acc;
acc["name"] = QVariant(name);
acc["start"] = QVariant(start);
acc["stop"] = QVariant(stop);
list.removeAt(i);
list.insert(i, QVariant(acc));
jda.save(QVariant(list), this->file);
loadAccounts();
}
示例8: addAccount
void AccountList::addAccount(QString name, int start, int stop)
{
JsonDataAccess jda;
QVariantList list = jda.load(this->file).value<QVariantList>();
QVariantMap acc;
acc["name"] = QVariant(name);
acc["start"] = QVariant(start);
acc["stop"] = QVariant(stop);
list.append(QVariant(acc));
jda.save(QVariant(list), this->file);
loadAccounts();
}
示例9: loadSavedState
void ApplicationUI::loadSavedState()
{
QString filePath(QDir::currentPath() + "/data/levelState.json");
if (QFile::exists(filePath)) {
JsonDataAccess jda;
QVariantMap state = jda.load(filePath).toMap();
if (jda.hasError())
return;
if (state.contains("levelAvailable")) {
int levelAvailable = state["levelAvailable"].toInt();
if (levelAvailable > 0) {
setLevelAvailable(levelAvailable);
}
}
}
qDebug() << "Level available" << m_levelAvailable;
}
示例10: 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;
}
示例11: 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);
}
}
}
示例12: onHttpFinished
void WeatherDataSource::onHttpFinished()
{
JsonDataAccess jda;
QVariantList weatherDataFromServer;
int httpStatus = -1; // controls the final behavior of this function
if (mReply->error() == QNetworkReply::NoError) {
// Load the data using the reply QIODevice.
weatherDataFromServer = jda.load(mReply).value<QVariantList>();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qDebug() << "JSON loading error:" << error.errorType() << " : " << error.errorMessage();
httpStatus = -2;
} else {
httpStatus = 200;
}
} else {
// An error occurred, try to get the http status code and reason
QVariant statusCode = mReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
QString reason = mReply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
if (statusCode.isValid()) {
httpStatus = statusCode.toInt();
}
qDebug() << "Network request to " << mReply->request().url().toString()
<< " failed with http status " << httpStatus << " " << reason;
}
// Now behave
switch (httpStatus) {
case 200:
loadNetworkReplyDataIntoDataBase(weatherDataFromServer);
break;
case 404:
if (mCursor.index == 0) {
// If we requested index 0 and didn't get an empty array it means the city does not exist and we should show an error
setErrorCode(WeatherError::InvalidCity);
} else {
// If we get a 404 in the middle of a data set it simply means there is no more data
emit noMoreWeather();
}
break;
case 503:
// TODO: perhaps try again a few times and eventually just stop? if we end up stopping and the list is empty, show an alert message. if the list isn't empty just stop fetching
setErrorCode(WeatherError::ServerBusy);
break;
case -2:
setErrorCode(WeatherError::JsonError);
break;
case 500:
default:
// The server crapped out, if we don't have any entries let the user know an error occurred, otherwise just stop fetching
setErrorCode(WeatherError::ServerError);
break;
}
// The reply is not needed now so we call deleteLater() function since we are in a slot.
mReply->deleteLater();
mReply = 0;
}