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. [SOLVED] Reference error in ListView highlight component
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Reference error in ListView highlight component

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 2.6k 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.
  • N Offline
    N Offline
    njeisecke
    wrote on last edited by
    #1

    I'm feeling as if I've started using Qt Quicks just 20 minutes ago...

    The following trivial code does not work.

    I cannot reference from the highlight component to the ListView that is in the same scope.

    Either I'm totally blind or there is actually something wrong inside Qt (4.8.1). I would appreciate any help!

    Main.qml
    @
    import QtQuick 1.1

    Column {
    width: 300
    height: 300

    Reel {
    id: reelInstance // setting some local id here
    }
    }
    @

    Reel.qml
    @
    import QtQuick 1.1

    ListView {
    id: reel
    width: 100
    height: 100

    property string someProperty: "Bla!"

    highlight: Text {
    // results in "ReferenceError: Can't find variable: reel"
    text: ">>> " + reel.someProperty
    }

    delegate: Text {
    // interestingly: this works as expected
    text: "M " + reel.someProperty + " - " + modelData
    }

    model: 10
    }

    @

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

      I see the same behavior in both 4.8.1 and 4.7.4. (Doesn't work for me either.)

      I don't know. Seems like that should work.

      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
      • N Offline
        N Offline
        njeisecke
        wrote on last edited by
        #3

        I also think that it should work. I've filed a bug:

        https://bugreports.qt-project.org/browse/QTBUG-26043

        1 Reply Last reply
        0
        • N Offline
          N Offline
          njeisecke
          wrote on last edited by
          #4

          This is fixed with d25fc4c63fa4512aa1cfc5ce3877e4d8632b3fec.

          Thanks!

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billouparis
            wrote on last edited by
            #5

            Hello,

            Anyone knows of a workaround for this issue. I would like it to work on the 4.8.1 version with no modification. Thank you.

            Bill

            1 Reply Last reply
            0
            • N Offline
              N Offline
              njeisecke
              wrote on last edited by
              #6

              You can use the ListView.view attached property.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                billouparis
                wrote on last edited by
                #7

                Exactly what I needed, thank you so much Njeisecke!

                Bill

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  njeisecke
                  wrote on last edited by
                  #8

                  Yeah, we Ant Farmers must stick together ;-)

                  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