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. Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results

Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results

Scheduled Pinned Locked Moved Solved General and Desktop
qfilesystemmodeqtreeviewqabstractitemmoqsortfilterprox
15 Posts 3 Posters 4.1k Views 2 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.
  • moffa13M moffa13

    Any help please

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @moffa13
    Add some qDebug() statement to see what index are sent and what it set pr index.
    I think its one of those cases where debugger and tools are more useful than guessing looking at code.

    1 Reply Last reply
    1
    • moffa13M Offline
      moffa13M Offline
      moffa13
      wrote on last edited by
      #7

      @mrjj said in Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results:

      @moffa13
      Add some qDebug() statement to see what index are sent and what it set pr index.
      I think its one of those cases where debugger and tools are more useful than guessing looking at code.

      If it was that simple I wouldn't have asked.

      qDebug is showing me correct paths before calling setData. The problem is that for whatever reason, some checkboxes won't get checked. I almost always get a different result whenever I run this code.

      qDebug in setData tells me that the function receives Qt::Checked but it's not the case.

      mrjjM 1 Reply Last reply
      0
      • moffa13M moffa13

        @mrjj said in Reimplementing QFileSystemModel Checkboxes using QMap inconsistent results:

        @moffa13
        Add some qDebug() statement to see what index are sent and what it set pr index.
        I think its one of those cases where debugger and tools are more useful than guessing looking at code.

        If it was that simple I wouldn't have asked.

        qDebug is showing me correct paths before calling setData. The problem is that for whatever reason, some checkboxes won't get checked. I almost always get a different result whenever I run this code.

        qDebug in setData tells me that the function receives Qt::Checked but it's not the case.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @moffa13
        Hi
        Hmm, i would suspect the QSet<QPersistentModelIndex>
        could contain incorrect indexes.
        Im wondering if QFileSystemModel might invalidate QPersistentModelIndexes i have seen with QSqlTableModel.

        moffa13M 1 Reply Last reply
        0
        • mrjjM mrjj

          @moffa13
          Hi
          Hmm, i would suspect the QSet<QPersistentModelIndex>
          could contain incorrect indexes.
          Im wondering if QFileSystemModel might invalidate QPersistentModelIndexes i have seen with QSqlTableModel.

          moffa13M Offline
          moffa13M Offline
          moffa13
          wrote on last edited by
          #9

          @mrjj It only has this behavior when I use QMap if I do this with QSet everything works fine. That's what I don't get

          mrjjM 1 Reply Last reply
          0
          • moffa13M moffa13

            @mrjj It only has this behavior when I use QMap if I do this with QSet everything works fine. That's what I don't get

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @moffa13
            Hmm. yes that is odd.
            One difference with Set/QMap is if u ask QMap for non existing value
            a default-constructed value is returned but you seem to check with contains so
            should not happen?

            1 Reply Last reply
            0
            • moffa13M Offline
              moffa13M Offline
              moffa13
              wrote on last edited by
              #11

              @mrjj

              Yeah, exactly, for me it should work.

              However I noticed something which may be useful. I added a QEventLoop when doing setData to look for the dataChanged signal but when I do this and I use qDebug to show the files returned by model::index, I get something like this :

              Normal dir is
              a.txt
              b.txt
              c.txt

              filePath in the loop returns this :

              a.txt
              b.txt
              b.txt

              And c.txt does not get checked which is also odd.

              mrjjM 1 Reply Last reply
              0
              • moffa13M moffa13

                @mrjj

                Yeah, exactly, for me it should work.

                However I noticed something which may be useful. I added a QEventLoop when doing setData to look for the dataChanged signal but when I do this and I use qDebug to show the files returned by model::index, I get something like this :

                Normal dir is
                a.txt
                b.txt
                c.txt

                filePath in the loop returns this :

                a.txt
                b.txt
                b.txt

                And c.txt does not get checked which is also odd.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #12

                @moffa13
                Hmm. you know how b.txt is included twice ?

                moffa13M 1 Reply Last reply
                0
                • mrjjM mrjj

                  @moffa13
                  Hmm. you know how b.txt is included twice ?

                  moffa13M Offline
                  moffa13M Offline
                  moffa13
                  wrote on last edited by
                  #13

                  @mrjj this is absolutely not normal. It' a for loop iterating from 0 to rowCount(parent). Then it uses model->index(i, 0, parent). So this is not possible to output twice the same file.

                  mrjjM 1 Reply Last reply
                  0
                  • moffa13M moffa13

                    @mrjj this is absolutely not normal. It' a for loop iterating from 0 to rowCount(parent). Then it uses model->index(i, 0, parent). So this is not possible to output twice the same file.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    @moffa13
                    Could you try to do the same for loop from say a button and use
                    no localEvent loop or anything like that and see if its
                    reproducible in other context ?

                    1 Reply Last reply
                    0
                    • moffa13M Offline
                      moffa13M Offline
                      moffa13
                      wrote on last edited by
                      #15

                      Ok I found what was causing this awful bug.

                      When I check if the map contains the index, I actually check the raw index not the QPersistantModelIndex so this is not the same object and I think qmap does not check equality using == operator .

                      So I have to iterate over the map and check using QPersistantModelIndex "==" operators which can compare from a QModelIndex.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved