Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TabBar and model update
Forum Updated to NodeBB v4.3 + New Features

TabBar and model update

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 702 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.
  • RomanoFXR Offline
    RomanoFXR Offline
    RomanoFX
    wrote on last edited by
    #1

    Hi,

    I build a QML model (ListModel) width a submodel.

    ListModel {
            id: modelstart
            ListElement { key: qsTr("Manuel"); option:  [
                    ListElement { choice: qsTr("Délais") },
                    ListElement { choice: qsTr("Date") }
                ]}
            ListElement { key: qsTr("Déclencheur"); option: [
                    ListElement { choice: qsTr("Voies logiques") },
                    ListElement { choice: qsTr("Voie Analogique")  },
                    ListElement { choice: qsTr("(OU) Voies") },
                    ListElement { choice: qsTr("(ET) Voies") },
                    ListElement { choice: qsTr("Pente Voies") }
                ]
            }
            ListElement { key: qsTr("Attente"); option:  [
                    ListElement { choice: qsTr("Délais") },
                    ListElement { choice: qsTr("Date") }
                ]
            }
            ListElement { key: qsTr("Automatique"); option:  [
                    ListElement { choice: qsTr("Délais") },
                    ListElement { choice: qsTr("Date") }
                ]}
        }
    

    I use TabBar for displaying all possibilities like this:

    TabBar {
                    id: tabBar2
                    width: parent.width
                    anchors.bottom: parent.bottom
                    
                    Repeater{
                        model: modelstart.get(tabBar.currentIndex).option
                        TabButton {
                            text: choice
                        }   
                    }
                }
    
                TabBar {
                    id: tabBar
                    width: parent.width
                    anchors.top: parent.top
                    
                    Repeater{
                        model:modelstart
                        TabButton {
                            text: key
                        }
                        
                    }
                    
                }
    

    But the application crashes when I change the tabBar currentIndex. Should I avoid the model update like this way?

    Thank you

    p3c0P 1 Reply Last reply
    0
    • RomanoFXR RomanoFX

      Hi,

      I build a QML model (ListModel) width a submodel.

      ListModel {
              id: modelstart
              ListElement { key: qsTr("Manuel"); option:  [
                      ListElement { choice: qsTr("Délais") },
                      ListElement { choice: qsTr("Date") }
                  ]}
              ListElement { key: qsTr("Déclencheur"); option: [
                      ListElement { choice: qsTr("Voies logiques") },
                      ListElement { choice: qsTr("Voie Analogique")  },
                      ListElement { choice: qsTr("(OU) Voies") },
                      ListElement { choice: qsTr("(ET) Voies") },
                      ListElement { choice: qsTr("Pente Voies") }
                  ]
              }
              ListElement { key: qsTr("Attente"); option:  [
                      ListElement { choice: qsTr("Délais") },
                      ListElement { choice: qsTr("Date") }
                  ]
              }
              ListElement { key: qsTr("Automatique"); option:  [
                      ListElement { choice: qsTr("Délais") },
                      ListElement { choice: qsTr("Date") }
                  ]}
          }
      

      I use TabBar for displaying all possibilities like this:

      TabBar {
                      id: tabBar2
                      width: parent.width
                      anchors.bottom: parent.bottom
                      
                      Repeater{
                          model: modelstart.get(tabBar.currentIndex).option
                          TabButton {
                              text: choice
                          }   
                      }
                  }
      
                  TabBar {
                      id: tabBar
                      width: parent.width
                      anchors.top: parent.top
                      
                      Repeater{
                          model:modelstart
                          TabButton {
                              text: key
                          }
                          
                      }
                      
                  }
      

      But the application crashes when I change the tabBar currentIndex. Should I avoid the model update like this way?

      Thank you

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @RomanoFX,
      I dont have an exact answer for your question as I too haven't explored these new controls. But I suspect there could be some problem with model change in tabBar2's Repeater. Whenever the current Index of tabBar is changed the binding is re-evaluated ( can be checked usingonModelChanged signal handler ) in tabBar2's Repeater and might be the source of crash.
      An alternative would be to do as follows:

      // Inside tabBar
      
      onCurrentIndexChanged: {
           for(var i=0; i<tabBar2.count; i++)
               tabBar2.itemAt(i).text = modelstart.get(currentIndex).option.get(i).choice
      }
      
      //Inside tabBar2
      
      Repeater{
          model: 2
          TabButton { }
      }
      

      157

      1 Reply Last reply
      1
      • RomanoFXR Offline
        RomanoFXR Offline
        RomanoFX
        wrote on last edited by
        #3

        Hi @p3c0,

        Thank you for that answer

        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