Converting a list/array 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
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
Q_INVOKABLE bool eveWriteXML(const QJsonObject &pqvarPortalItemResult);
HomeController.cpp
bool HomeController::eveWriteXML(const QJsonObject &pqvarPortalItemResult) { QVariantMap jsonQVariantMap = pqvarPortalItemResult.toVariantMap(); for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) { QVariant objQVariant = iter.key(); QVariant objQVariant1 = iter.value(); QString strTitleValue = objQVariant1.toMap().values("title").value(0).toSt ring(); QString strUrlValue = objQVariant1.toMap().values("url").value(0).toStri ng(); QString strOwnerValue = objQVariant1.toMap().values("owner").value(0).toSt ring(); QString strItemIdValue = objQVariant1.toMap().values("itemId").value(0).toS tring(); }
Thanks In advance.
-
@Mathan-M
Not sure about the performance issues but the way you are trying to extract JSON values seems to be wrong.iter.value()
is going to return aQVariant
ofQString
's because
idPortalSearchItems.results[ii].title
,idPortalSearchItems.results[ii].owner
... are all strings.
So it should be replaced as:QVariant v = iter.value(); QString strTitleValue = v.toString(); ...
-
Hi,
What does a run through the debugger tell you ?
-
@Mathan-M
Not sure about the performance issues but the way you are trying to extract JSON values seems to be wrong.iter.value()
is going to return aQVariant
ofQString
's because
idPortalSearchItems.results[ii].title
,idPortalSearchItems.results[ii].owner
... are all strings.
So it should be replaced as:QVariant v = iter.value(); QString strTitleValue = v.toString(); ...
-