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. How to Identify Model In Use?

How to Identify Model In Use?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 437 Views 3 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I have a Repeater for a custom TabBar. The contents of the TabButtons is to depend on which model is applied to the repeater. Here's what I'm trying:

    Repeater {
        model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
        Tabbutton_custom {
            text: qsTr(model.name)
            icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")
            bgColor: auxTabBar.bgColor
            imageSize: auxTabBar.height / 2
        }
    }
    

    My error seems to be here:

    icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")
    

    The "model === prefsModel" always seems to evaluate as false. I imagine I'm improperly forming the test. How can I determine which model is in use here?

    Thanks...

    piervalliP 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @piervalli interesting. It's not working for me; perhaps I'm not using it properly?

      ListModel {
          id: prefsModel
          objectName: "prefsModel"
          ListElement { name: "Profile && Accounts"; image: "" }
          ListElement { name: "Device"; image: ""}
          ListElement { name: "Site"; image: "" }
          ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" }
      }
      
      Repeater {
          model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
          Tabbutton_custom {
              text: qsTr(model.name)
              icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("")
              bgColor: auxTabBar.bgColor
              imageSize: auxTabBar.height / 2
          }
      }
      
      fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #4

      @mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".

      Repeater {
          id: repeater
          model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
          Tabbutton_custom {
              text: qsTr(repeater.model.name)
              icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("")
              bgColor: auxTabBar.bgColor
              imageSize: auxTabBar.height / 2
          }
      }
      

      Or you could use parent.model in this case.

      Are you not getting all sorts of errors in the application output?

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      1
      • mzimmersM mzimmers

        Hi all -

        I have a Repeater for a custom TabBar. The contents of the TabButtons is to depend on which model is applied to the repeater. Here's what I'm trying:

        Repeater {
            model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
            Tabbutton_custom {
                text: qsTr(model.name)
                icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")
                bgColor: auxTabBar.bgColor
                imageSize: auxTabBar.height / 2
            }
        }
        

        My error seems to be here:

        icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")
        

        The "model === prefsModel" always seems to evaluate as false. I imagine I'm improperly forming the test. How can I determine which model is in use here?

        Thanks...

        piervalliP Offline
        piervalliP Offline
        piervalli
        wrote on last edited by
        #2

        @mzimmers
        In the object there is the property objectName, I used it in a similar case.

        mzimmersM 1 Reply Last reply
        1
        • piervalliP piervalli

          @mzimmers
          In the object there is the property objectName, I used it in a similar case.

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #3

          @piervalli interesting. It's not working for me; perhaps I'm not using it properly?

          ListModel {
              id: prefsModel
              objectName: "prefsModel"
              ListElement { name: "Profile && Accounts"; image: "" }
              ListElement { name: "Device"; image: ""}
              ListElement { name: "Site"; image: "" }
              ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" }
          }
          
          Repeater {
              model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
              Tabbutton_custom {
                  text: qsTr(model.name)
                  icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("")
                  bgColor: auxTabBar.bgColor
                  imageSize: auxTabBar.height / 2
              }
          }
          
          fcarneyF 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @piervalli interesting. It's not working for me; perhaps I'm not using it properly?

            ListModel {
                id: prefsModel
                objectName: "prefsModel"
                ListElement { name: "Profile && Accounts"; image: "" }
                ListElement { name: "Device"; image: ""}
                ListElement { name: "Site"; image: "" }
                ListElement { name: "ZONE"; image: "qrc:/icons/add.svg" }
            }
            
            Repeater {
                model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
                Tabbutton_custom {
                    text: qsTr(model.name)
                    icon.source: (model.objectName === "prefsModel" && model.image !== "") ? model.image : Qt.resolvedUrl("")
                    bgColor: auxTabBar.bgColor
                    imageSize: auxTabBar.height / 2
                }
            }
            
            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #4

            @mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".

            Repeater {
                id: repeater
                model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
                Tabbutton_custom {
                    text: qsTr(repeater.model.name)
                    icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("")
                    bgColor: auxTabBar.bgColor
                    imageSize: auxTabBar.height / 2
                }
            }
            

            Or you could use parent.model in this case.

            Are you not getting all sorts of errors in the application output?

            C++ is a perfectly valid school of magic.

            mzimmersM 1 Reply Last reply
            1
            • fcarneyF fcarney

              @mzimmers This looks like a scoping issue. Unless the Repeater is the top level Item the lower Items won't see the "model".

              Repeater {
                  id: repeater
                  model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
                  Tabbutton_custom {
                      text: qsTr(repeater.model.name)
                      icon.source: (repeater.model.objectName === "prefsModel" && repeater.model.image !== "") ? repeater.model.image : Qt.resolvedUrl("")
                      bgColor: auxTabBar.bgColor
                      imageSize: auxTabBar.height / 2
                  }
              }
              

              Or you could use parent.model in this case.

              Are you not getting all sorts of errors in the application output?

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #5

              @fcarney well...that fixed it. Interestingly enough, I don't find it necessary to scope the model in the text: line...not sure why it would be different for item.source.

              And no, I'm not getting any errors.

              But...I'll consider it solved. Thanks!

              fcarneyF 1 Reply Last reply
              2
              • mzimmersM mzimmers has marked this topic as solved on
              • mzimmersM mzimmers

                @fcarney well...that fixed it. Interestingly enough, I don't find it necessary to scope the model in the text: line...not sure why it would be different for item.source.

                And no, I'm not getting any errors.

                But...I'll consider it solved. Thanks!

                fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #6

                @mzimmers Yeah, that is weird.

                C++ is a perfectly valid school of magic.

                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