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. get children of a listview

get children of a listview

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 1.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I wrote:

     int numero_children = _listView->children().count();
                    QList<QString> list;
    
    
                    for (int i=0; i<numero_children; i++)
    
                    {
    
                    QModelIndex mi3 = index.child(i,0);
                    QVariant data_child = _listView->model()->data(mi3);
                    QString data_c = data_child.toString();
                    list.insert(i,data_child.toString());
    
    
    
                  }
    

    but list is empty

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

      Hope you are talking about QListView. What are looking for here as children of QListView ? What is the expectation ?

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

      ? 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Hope you are talking about QListView. What are looking for here as children of QListView ? What is the expectation ?

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @dheerendra I click on a dir:

         QModelIndex index = _listView->currentIndex();
        

        and then I want find out what there is inside the dir...how must I write?

        jsulmJ 1 Reply Last reply
        0
        • ? A Former User

          @dheerendra I click on a dir:

           QModelIndex index = _listView->currentIndex();
          

          and then I want find out what there is inside the dir...how must I write?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @vale88 Did you at least check the value of numero_children?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply
          0
          • jsulmJ jsulm

            @vale88 Did you at least check the value of numero_children?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @jsulm 0_1560249653633_Cattura.PNG

            Inside the dir there is this, numero_children is 7, because it counts also the file inside Nuova cartella, but I want to see only this 4 children

            jsulmJ 1 Reply Last reply
            0
            • ? A Former User

              @jsulm 0_1560249653633_Cattura.PNG

              Inside the dir there is this, numero_children is 7, because it counts also the file inside Nuova cartella, but I want to see only this 4 children

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @vale88 What I wanted to know is the value of numero_children after executing this line of code

              int numero_children = _listView->children().count();
              

              If list is empty then the for loop was not executed.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              ? 1 Reply Last reply
              0
              • jsulmJ jsulm

                @vale88 What I wanted to know is the value of numero_children after executing this line of code

                int numero_children = _listView->children().count();
                

                If list is empty then the for loop was not executed.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                @jsulm numero_children = 7
                but numero_children must be 4, because inside I have a dir and 3 files, the for loop is executed, but I think I write bad this line:

                QVariant data_child = _listView->model()->data(mi3);

                because data_child is invalid

                ? 1 Reply Last reply
                0
                • ? A Former User

                  @jsulm numero_children = 7
                  but numero_children must be 4, because inside I have a dir and 3 files, the for loop is executed, but I think I write bad this line:

                  QVariant data_child = _listView->model()->data(mi3);

                  because data_child is invalid

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @vale88 0_1560250332104_Cattura.PNG

                  in debug I have this

                  1 Reply Last reply
                  0
                  • Crawl.WC Offline
                    Crawl.WC Offline
                    Crawl.W
                    wrote on last edited by Crawl.W
                    #9

                    @vale88

                    int numero_children = _listView->children().count();
                    

                    The only possibility is the numero_children equals 0, check your _listView->children().
                    I think you just debug with put breakpoint int for cycle.
                    If it's impossible condition, check your funcation stack.Is there a stack overflow?

                    ? 1 Reply Last reply
                    0
                    • Crawl.WC Crawl.W

                      @vale88

                      int numero_children = _listView->children().count();
                      

                      The only possibility is the numero_children equals 0, check your _listView->children().
                      I think you just debug with put breakpoint int for cycle.
                      If it's impossible condition, check your funcation stack.Is there a stack overflow?

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      @Crawl.W I just done it, no because numero_children = 7

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #11

                        What model are you using?

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        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