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. [SOLVED]selectedIndexes returns duplicates
Qt 6.11 is out! See what's new in the release blog

[SOLVED]selectedIndexes returns duplicates

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.1k 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.
  • saeedhardanS Offline
    saeedhardanS Offline
    saeedhardan
    wrote on last edited by
    #1

    Hi ,
    i have a treeview, inside it i have QFileSystemModel ,
    in the treeview i allow :
    @
    ui->treeView->setSelectionMode(QAbstractItemView::MultiSelection);
    @

    This is the code to read the selections :

    @
    QStringList paths;
    QModelIndexList indexes_list = ui->treeView->selectionModel()->selectedIndexes();
    for(QModelIndexList::iterator it = indexes_list.begin();it != indexes_list.end();
    it++){
    paths.append(files->fileInfo((*it)).absoluteFilePath());
    }
    path = paths.join(";");
    @

    From the treeview i went to a directory where there is only two files and selected them using Ctrl+left mouse click .
    when the above code is reached i get 4 duplicates from each file path inside the :
    @
    QStringList paths;
    @

    above .

    what am i doing wrong ?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      A row in the QFileSystemModel has 4 columns (name, size, type, time). So when selecting a line you receive 4 selected model indexes.

      So it depends what you code exactly does in the line
      @
      files->fileInfo((*it)
      @

      You should only process model indexes of the column 0 in your case.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • saeedhardanS Offline
        saeedhardanS Offline
        saeedhardan
        wrote on last edited by
        #3

        files is my QFileSystemModel , how do i read only the first column ?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @
          if( (*it).column() == 0 )
          paths.append(files->fileInfo((*it)).absoluteFilePath());
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • saeedhardanS Offline
            saeedhardanS Offline
            saeedhardan
            wrote on last edited by
            #5

            thanks a lot it worked .

            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