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. Reference Error: modal data is not defined - QML
Forum Updated to NodeBB v4.3 + New Features

Reference Error: modal data is not defined - QML

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

    Hi,

    This is the code that i am using .

    Window {
    ComboBox {
    x:6
    y:6
    width: 200
    model:ListModel {
    id: cbItems
    ListElement { text: "Radio 1"; color: "Yellow"}
    ListElement { text: "Radio 2"; color: "Green"}
    ListElement { text: "Radio 3"; color: "Brown"}
    }

           }
    

    }

    And i am getting the error : modal data is not defined.

    ODБOïO 1 Reply Last reply
    0
    • J Jayasuriya

      Hi,

      This is the code that i am using .

      Window {
      ComboBox {
      x:6
      y:6
      width: 200
      model:ListModel {
      id: cbItems
      ListElement { text: "Radio 1"; color: "Yellow"}
      ListElement { text: "Radio 2"; color: "Green"}
      ListElement { text: "Radio 3"; color: "Brown"}
      }

             }
      

      }

      And i am getting the error : modal data is not defined.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi IMHO the error message has nothing to do with the code you show us

      GrecKoG 1 Reply Last reply
      0
      • ODБOïO ODБOï

        hi IMHO the error message has nothing to do with the code you show us

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @ODБOï said in Reference Error: modal data is not defined - QML:

        hi IMHO the error message has nothing to do with the code you show us

        Why do you say that?
        The error message has everything to do with the code shown here. And the mistake can be seen without running the code. If you don't, running the code and interacting with it will confirm that this error message is output.

        @Jayasuriya When using a model with roles (ListModel is one) in a ComboBox you need to define the textRole property (and potentially the valueRole) to use the default delegate. You could also provide your own delegate.

            ComboBox {
                model: ListModel {
                    id: cbItems
                    ListElement { text: "Radio 1"; color: "Yellow"}
                    ListElement { text: "Radio 2"; color: "Green"}
                    ListElement { text: "Radio 3"; color: "Brown"}
                }
                textRole: "text"
            }
        
            ComboBox {
                model: ListModel {
                    id: cbItems
                    ListElement { text: "Radio 1"; color: "Yellow"}
                    ListElement { text: "Radio 2"; color: "Green"}
                    ListElement { text: "Radio 3"; color: "Brown"}
                }
                delegate: ItemDelegate {
                    contentItem: RowLayout {
                        spacing: 8
                        Rectangle {
                            color: model.color
                            Layout.fillHeight: true
                            Layout.preferredWidth: height
                        }
                        Label {
                            Layout.fillHeight: true
                            Layout.fillWidth: true
                            text: model.text
                        }
                    }
                }
            }
        
        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