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. QQmlListProperty, ListView and delegate
Forum Updated to NodeBB v4.3 + New Features

QQmlListProperty, ListView and delegate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 1.8k 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.
  • C Offline
    C Offline
    cosmoff
    wrote on last edited by cosmoff
    #1

    Hello everybody

    I make a QQmlListProperty<MagicSquare> and I would like to display the attribut 'label' from my class MagicSquare but it does not work. I think that my problem come from QML and not of Qt, so I do not show my code source execept if you need it.

    I have in my source code (magicSquareModel.h) :
    Q_PROPERTY ( QQmlListProperty<MagicSquare> magicSquareList READ getMagicSquareList NOTIFY magicSquareListChanged )

    We can acces to QQmlList thanks to : qmlContext->setContextProperty ( "magicSquareModel", m_magicSquareModel );

    So this is my code in Qml :

    ListView{

    width: parent.width
    height: parent.height
    model: magicSquareModel.magicSquareList
    clip: true
    
    delegate: SimulationMagicSquare{
        width: parent.width * 0.75
        height: virtualModeGraphicIdentity.buttonHeight
        anchors {
            horizontalCenter: parent.horizontalCenter
        }
    
        title: model.label
    
    }
    

    }
    my terminal returns : Unable to assign [undefined] to QString where there is title: model.label (title is just a Text{} )
    have you got an idea of the problem ?

    Thanks.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      magicSquareModel.magicSquareList is not a model. It is just a list property.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cosmoff
        wrote on last edited by
        #3

        Thanks for you answer.

        But how can I see my attribut from my magicSquareList in the qml ?

        J.HilkJ 1 Reply Last reply
        0
        • C cosmoff

          Thanks for you answer.

          But how can I see my attribut from my magicSquareList in the qml ?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @cosmoff said in QQmlListProperty, ListView and delegate:

          Thanks for you answer.

          But how can I see my attribut from my magicSquareList in the qml ?

          inside your delegate, you cann access the underlying data via modelData

          delegate: SimulationMagicSquare{
              width: parent.width * 0.75
              height: virtualModeGraphicIdentity.buttonHeight
              anchors {
                  horizontalCenter: parent.horizontalCenter
              }
          
              title: modelData.label //here
          
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cosmoff
            wrote on last edited by cosmoff
            #5

            it does not work,

            the code is :

            ListView{
            
                            id:virtualModeList
                            width: parent.width
                            height: parent.height
                            model: virtualModeModel.virtualModeList
                            clip: true
            
                            delegate: SimulationButton{
                                width: parent.width * 0.75
                                height: virtualModeGraphicIdentity.buttonHeight
                                anchors {
                                    horizontalCenter: parent.horizontalCenter
                                }
            
                                title: modelData.label
            
                            }
            
            
                        }
            

            the terminal returns : Unable to assign [undefined] to QString

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              What is the data you are trying to expose ? Is it that you have to do QQMLPropertyList ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cosmoff
                wrote on last edited by cosmoff
                #7

                I make a :
                QQmlListProperty<MagicSquare> MagicSquareModel::getMagicSquareList()
                {
                return QQmlListProperty<MagicSquare>(this, &m_MagicSquareList,
                &MagicSquareModel::MagicSquareListCount,
                &MagicSquareModel::MagicSquareListAt);
                }

                in my class MagicSquare I have an attribut which is QString label and i want to display on the qml

                J.HilkJ 1 Reply Last reply
                0
                • C cosmoff

                  I make a :
                  QQmlListProperty<MagicSquare> MagicSquareModel::getMagicSquareList()
                  {
                  return QQmlListProperty<MagicSquare>(this, &m_MagicSquareList,
                  &MagicSquareModel::MagicSquareListCount,
                  &MagicSquareModel::MagicSquareListAt);
                  }

                  in my class MagicSquare I have an attribut which is QString label and i want to display on the qml

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #8

                  @cosmoff said in QQmlListProperty, ListView and delegate:

                  in my class MagicSquare I have an attribut which is QString label and i want to display on the qml

                  that has to be a Q_PROPERTY or a function that you made available to QML via Q_INVOKABLE


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • C Offline
                    C Offline
                    cosmoff
                    wrote on last edited by
                    #9

                    Its= works! I forget to put a Q_PROPERTY for the attribut label...

                    thanks for your help !

                    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