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. TypeError: Result of expression 'previousMenu.get(i)' [undefined] is not an object.
Forum Updated to NodeBB v4.3 + New Features

TypeError: Result of expression 'previousMenu.get(i)' [undefined] is not an object.

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 2.9k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Alcatraz
    wrote on last edited by
    #1

    im getting a little lost on why this is happening to me

    if i do console.log("Text = "+ previousMenu.get(i).name)
    works shows me the text but when i try to pass on that value to another qml like my other model like so

    subMenuModel.iName = previousMenu.get(i).name

    i get the error

    TypeError: Result of expression 'previousMenu.get(i)' [undefined] is not an object.

    show you the code

    @
    function backButtonClicked() {
    for (var i = 0; i < previousMenu.count; ++i)
    {
    previousMenu.remove(i)
    subMenuModel.iName = previousMenu.get(i).name

    // want an if i = null
    // do something here like change the state of the back button to disabled
    }
    }
    @

    every item thats clicked gets appended to a listmodel then what i want to do is remove the LAST one in the list ie i = 1 remove 1 get 0
    if i is null dosomething

    how can i achieve this ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vulee
      wrote on last edited by
      #2

      If i is the index of the last item in the list, previousMenu.remove(i) would remove the last one, then previousMenu.get(i) would return undefine.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alcatraz
        wrote on last edited by
        #3

        yes thats why im trying to make it stop at null and if null change the state of my back button to disabled

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alcatraz
          wrote on last edited by
          #4

          any solutions ?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            I'm not sure exactly what you're trying to do.

            If you're trying to do something for all elements and then do something special with the last one, why not loop from 0 to count-1, then handle the special case of the last item on it's own?

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            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