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. Is it possible to assign different types to a role in a ListElement ?
Qt 6.11 is out! See what's new in the release blog

Is it possible to assign different types to a role in a ListElement ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 526 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.
  • L Offline
    L Offline
    LRDPRDX
    wrote on last edited by
    #1

    Dear Qt'ers, please, take a look at the following code:

    ListModel {
        ListElement {
            display: "foo";
            type: EType.EText; // EType is my own enum, loader selects the source component based on the value of this role
            comboData: []
        }
    
        ListElement {
            display: 1; //<-- want to use index 1 in the combo box
            type: EType.EList;
            comboData: [ ListElement { display: "one" },
                         ListElement { display: "two" } ]
        }
    }
    

    This is a mock table of one implemented in C++. Everything looks fine except that I'm getting a warning :

    <Unknown File>: Can't assign to existing role 'display' of different type [Number -> String]

    Again, the index of the combo box is set correctly, the value is "two", but I'm wondering how do I handle this warning ?

    Axel SpoerlA 1 Reply Last reply
    0
    • L LRDPRDX

      Dear Qt'ers, please, take a look at the following code:

      ListModel {
          ListElement {
              display: "foo";
              type: EType.EText; // EType is my own enum, loader selects the source component based on the value of this role
              comboData: []
          }
      
          ListElement {
              display: 1; //<-- want to use index 1 in the combo box
              type: EType.EList;
              comboData: [ ListElement { display: "one" },
                           ListElement { display: "two" } ]
          }
      }
      

      This is a mock table of one implemented in C++. Everything looks fine except that I'm getting a warning :

      <Unknown File>: Can't assign to existing role 'display' of different type [Number -> String]

      Again, the index of the combo box is set correctly, the value is "two", but I'm wondering how do I handle this warning ?

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @LRDPRDX
      You can’t assign different types to the same role, if you populate via QJSValue.
      In that case you could just use another data role, e.g. edit instead of display.
      I recently played with a combo box in a table view and ended up doing it that way.

      Software Engineer
      The Qt Company, Oslo

      L 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @LRDPRDX
        You can’t assign different types to the same role, if you populate via QJSValue.
        In that case you could just use another data role, e.g. edit instead of display.
        I recently played with a combo box in a table view and ended up doing it that way.

        L Offline
        L Offline
        LRDPRDX
        wrote on last edited by
        #3

        @Axel-Spoerl Thank you. Actually, I've found that putting a string also works :

        ListElement {
            display: "1"
            ...
        }
        
        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