ListModel Append Data Application is Crash
-
Hello, my application quits interestingly when I add data to my list model. Is it because the data is an object list, I wonder if it is null data?
13:30:53: The program has unexpectedly finished. 13:30:53: The process was ended forcefully.
I did some experimentation and came to the following conclusion. If I try a code like the following, it adds it successfully, but I have problems accessing the data.
for(let i = 0; i < modelData.length; i++) { dataModel.append({'event': modelData[i]}) }
This way my app crashes
for(let i = 0; i < modelData.length; i++) { dataModel.append(modelData[i]) }
JSON data looks like
[ { "id": "5c9dfa7e99bab859223e8026", "name": "Example1", "category": { "iso": "ESP", "name": "Esp" }, "games": [ { "id": "5f4d8f99d458a829dc651e0c", "properties": { "host": { "id": "5c9dfc4c99bab85b3776460a", "name": "Host 1", "image": "team/679759d9d930550fb50a5d30ba313fb196d55e3f92770f30dc383352cbf578ba.png" } } }, { "id": "5f4d8f99d458a829dc651e0c", "properties": { "host": { "id": "5c9dfc4c99bab85b3776460a", "name": "Host 2", "image": "team/679759d9d930550fb50a5d30ba313fb196d55e3f92770f30dc383352cbf578ba.png" } } } ] }, { "id": "5c9dfa7e99bab859223e8026", "name": "Example2", "category": { "iso": "ASP", "name": "ASP" }, "games": [ { "id": "5f4d8f99d458a829dc651e0c", "properties": { "host": { "id": "5c9dfc4c99bab85b3776460a", "name": "Host 1", "image": "team/679759d9d930550fb50a5d30ba313fb196d55e3f92770f30dc383352cbf578ba.png" } } }, { "id": "5f4d8f99d458a829dc651e0c", "properties": { "host": { "id": "5c9dfc4c99bab85b3776460a", "name": "Host 2", "image": "team/679759d9d930550fb50a5d30ba313fb196d55e3f92770f30dc383352cbf578ba.png" } } } ] } ]
-
What could be wrong? How can I add my data directly as follows ? In this way, it is necessary to access my data more easily and to use section, otherwise I do not know how to pass data to the section property.
for(let i = 0; i < modelData.length; i++) { dataModel.append(modelData[i]) }
-
@NullByte And what does the stack trace tell you?
-
@NullByte
Although I'm not sure whether it will really clarify: get rid of your two screenshots showing the disassembly --- it doesn't help us --- and show just the stack trace, which you currently have going back to level #11 and we need to see going back further all the way into your code. -
-
@NullByte
Well, that's not the stack trace window, which you did show, but only as far as level #11, and I said you ought show the rest of it.But never mind, maybe that error message you show now is enough for you to correct?
-
@JonB In fact, I mentioned in my first post that I had concerns about this issue. I did some work on this, I tried to eliminate the null values, but after a few attempts I found that it was not useful. Maybe I was not a QML newbie. Can you help me? I tried something like this to remove null values
JSON.parse(xhr.responseText.replace(/null/g, '""'))
<Unknown File>: Can't assign to existing role 'videoId' of different type [Number -> String]
-
@NullByte
-
Your "Can't assign ... [Number -> String]" does not look like it would come from that line, more perhaps from trying to parse
null
or""
as a number somewhere else. -
I'm not sure your
xhr.responseText.replace(/null/g, '""')
will work.For one thing, Pythonnull
isNone
. You should test? To cover that correctly I would go:
text = xhr.responseText if text is None: text = ""
EDIT Whoops, you are JavaScript, not Python, I don't do QML! :)
I'm still not sure about your
replace()
onnull
. What about:text = xhr.responseText; if text == null text = "";
This should allow for either
null
orundefined
in JS. -
-
It's work
var tmpData = JSON.parse(xhr.responseText.replace(/null/g, '""')) if(tmpData[z].games[d].videoId === null || tmpData[z].games[d].videoId === undefined || tmpData[z].games[d].videoId === "") { tmpData[z].games[d].videoId = 0 }