I am loading JSON from a web service with a QNetworkRequest
which I then put into a JsonDataAccess
object. I can parse the JSON and everything is fine.
But I want to format the JSON string to HTML and display it in a WebView which seems to not work from the thread that the finished(QNetworkReply*)
signal uses, since it's supposed to be non-UI-blocking.
However, I can add markers to a MapView
with the very same method. But updating the WebView
does not work. How do I get to the main thread to update the WebView?
Here's the method (slot) I use at the moment:
void ApplicationUI::onLoadJsonFinished(QNetworkReply* reply) {
JsonDataAccess jda;
jsonData = jda.load(reply);
qDebug() << "Received JSON data: " << jsonData;
QVariant result = jsonData.value<QVariantMap>();
QString addressTitle = result.toMap().value("address").toMap().value("title").toString();
QObject* webViewAsQObject = root->findChild<QObject*>(
QString("imprintWebViewObj"));
if (webViewAsQObject) {
WebView* webView = qobject_cast<bb::cascades::WebView*>(
webViewAsQObject);
QString html = QString("<h1>foo</h1>");
qDebug() << "Loading html into webview: " << html;
webView->setHtml(html);
}
}
And this is the qml file:
import bb.cascades 1.2
Page {
Container {
layout: DockLayout {
}
Container {
Container {
leftPadding: 20
topPadding: 30
bottomPadding: 30
Label {
text: "Impressum"
textStyle.fontFamily: "Georgia"
textStyle.fontSize: FontSize.Large
}
ScrollView {
Container {
background: Color.create("#f8f8f8")
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
WebView {
id: imprintWebView
objectName: "imprintWebViewObj"
}
}
}
}
} // Container Content end
}
}