Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListModel Append Data Application is Crash
Forum Updated to NodeBB v4.3 + New Features

ListModel Append Data Application is Crash

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    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"
                        }
                    }
                }
            ]
        }
    ]
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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])
              }
      
      jsulmJ 1 Reply Last reply
      0
      • ? A Former User

        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])
                }
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @NullByte And what does the stack trace tell you?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        ? 1 Reply Last reply
        0
        • jsulmJ jsulm

          @NullByte And what does the stack trace tell you?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          @jsulm

          edited

          JonBJ 1 Reply Last reply
          0
          • ? A Former User

            @jsulm

            edited

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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.

            ? 1 Reply Last reply
            0
            • JonBJ JonB

              @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.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @JonB @jsulm Sorry for this. I used console.trace() command for stack trace and got an output like

              setFixtureData (qrc:/AllGames.qml:732)
              onCompleted (qrc:/AllGames.qml:726)
               (qrc:/goalkolik.js:25)
              <Unknown File>: topIndex is null. Adding an object with a null member does not create a role for it.
              
              JonBJ 1 Reply Last reply
              0
              • ? A Former User

                @JonB @jsulm Sorry for this. I used console.trace() command for stack trace and got an output like

                setFixtureData (qrc:/AllGames.qml:732)
                onCompleted (qrc:/AllGames.qml:726)
                 (qrc:/goalkolik.js:25)
                <Unknown File>: topIndex is null. Adding an object with a null member does not create a role for it.
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @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?

                ? 1 Reply Last reply
                0
                • JonBJ JonB

                  @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?

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #8

                  @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]
                  
                  JonBJ 1 Reply Last reply
                  0
                  • ? A Former User

                    @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]
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @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, Python null is None. 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() on null. What about:

                    text = xhr.responseText;
                    if text == null
                        text = "";
                    

                    This should allow for either null or undefined in JS.

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by A Former User
                      #10

                      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
                      }
                      
                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved