converting list to JSON - performance issue.
Hi,
I want to pass the PortalSearchItems list to be passed from qml to Cpp. Eventhough, I can get the result, app got just killed, when this code executes. I assume performance issue.
Code Snippet: main.qml
--------------------------------------
Code:
var varidPortalSearchItemsCount = idPortalSearchItems.totalResults;
var vartextJson = "";
for (var ii = 0; ii <= varidPortalSearchItemsCount -1 ;ii++)
{
vartextJson += '{"title":"'+ idPortalSearchItems.results[ii].title +'"
,"owner":"'+ idPortalSearchItems.results[ii].owner +'"
,"url":"'+ idPortalSearchItems.results[ii].url +'"
,"itemId":"'+ idPortalSearchItems.results[ii].itemId +'"
}' + ',';
}
vartextJson = vartextJson.substring(0, vartextJson.length-1) + ']';
vartextJson = '[' + vartextJson;
var varJsonString =JSON.parse(vartextJson);
objHomeController.eveWriteXML(varJsonString);
HomeController.h
--------------------------
Code:
Q_INVOKABLE bool eveWriteXML(const QJsonObject &pqvarPortalItemResult);
HomeController.cpp
--------------------------
Code:
bool HomeController::eveWriteXML(const QJsonObject &pqvarPortalItemResult)
{
QVariantMap jsonQVariantMap = pqvarPortalItemResult.toVariantMap();
for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) {
QString strTitleValue
= objQVariant1.
toMap().
values("title").
value(0).
toString();
QString strUrlValue
= objQVariant1.
toMap().
values("url").
value(0).
toString();
QString strOwnerValue
= objQVariant1.
toMap().
values("owner").
value(0).
toString();
QString strItemIdValue
= objQVariant1.
toMap().
values("itemId").
value(0).
toString();
}
Thanks In advance.
Re: converting list to JSON - performance issue.
A lot of processing in QML but your choice to do that.
One thing you could avoid in the C++ code it to convert objQVariant1 into a map several times.
And calling just value(key) instead of values(key).value(0)
Also "I assume performance issue" is a no-go. Never assume, always measure.
Cheers,
_
Re: converting list to JSON - performance issue.
Hi,
for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) {
QVariant objQVariant = iter.key();//Gives the value of Iteration - 0,1....
calling just value(key)
Some code snippet Please.
Re: converting list to JSON - performance issue.
Quote:
Originally Posted by
Mathan
QVariant objQVariant = iter.key();//Gives the value of Iteration - 0,1....
No, gives the key of the iteration.
Actually a QString.
Quote:
Originally Posted by
Mathan
calling just value(key)
Some code snippet Please.
Really? You need a code snippet for a single method call on an object?
Code:
map.value("title");
Cheers,
_