void AppModel::handleGeoNetworkData(QObject *replyObj) { QNetworkReply *networkReply = qobject_cast<QNetworkReply*>(replyObj); if (!networkReply) { hadError(false); // should retry? return; } if (!networkReply->error()) { d->nErrors = 0; if (!d->throttle.isValid()) d->throttle.start(); d->minMsBeforeNewRequest = d->baseMsBeforeNewRequest; //convert coordinates to city name QJsonDocument document = QJsonDocument::fromJson(networkReply->readAll()); QJsonObject jo = document.object(); QJsonValue jv = jo.value(QStringLiteral("name")); const QString city = jv.toString(); qCDebug(requestsLog) << "got city: " << city; if (city != d->city) { d->city = city; emit cityChanged(); refreshWeather(); } } else { hadError(true); } networkReply->deleteLater(); }
QVariant QuickInterpreter::call(QSObject ctx, const QString &func, const QSList &args) { if (shuttingDown) return QVariant(); QSEngine::call(&ctx, func, args); if (hadError()) emit runtimeError(); // Make sure we dereference the engines return value to avoid pooling QVariant a = convertToArgument(returnValue()); setReturnValue(QSObject()); return a; }
/*! Returns the stack trace describing the call stack of the last reported error if there was an error; otherwise returns an empty stack trace. */ QSStackTrace QSInterpreter::stackTrace() const { QSStackTrace st; #ifdef QSDEBUGGER if (!hadError()) return st; QValueList<QuickDebuggerStackFrame> qtrace = d->interpreter->debuggerEngine()->backtrace(); for (QValueList<QuickDebuggerStackFrame>::ConstIterator it = qtrace.begin(); it != qtrace.end(); ++it) { QSStackFrame frame((*it).function, d->interpreter->nameOfSourceId((*it).sourceId), (*it).line, d->interpreter->objectOfSourceId((*it).sourceId) ); st << frame; } #endif return st; }
QVariant QuickInterpreter::execute(QObject *obj, const QString &c, const QString &name) { QString code = c + QString::fromLatin1("\n"); int sourceId = debugger ? debugger->freeSourceId() : -1; if(!name.isNull() && sourceId >= 0) sourceIdNames[sourceId] = name; QSObject t, oldThis; if (obj) { if (!name.isNull() && sourceId >= 0) addSourceId(sourceId, obj); if (!hasTopLevelParent(obj)) addTopLevelObject(obj); t = wrap(obj); oldThis = env()->thisValue(); env()->setThisValue(t); } QSEngine::evaluate(t, code); // restore this value if (obj) env()->setThisValue(oldThis); if (hadError()) if(errorType() == QSErrParseError) emit parseError(); else emit runtimeError(); // Make sure we dereference the engines return value to avoid pooling QVariant a = convertToArgument(returnValue()); setReturnValue(QSObject()); return a; }
/*! Returns the error message that was last reported if there was an error; otherwise returns QString::null */ QString QSInterpreter::errorMessage() const { return hadError() ? d->interpreter->errorMessages().first() : QString::null ; }