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 2.9k 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.
  • M moffa13
    20 Sept 2018, 10:38

    Any help please

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 20 Sept 2018, 10:57 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
    • M Offline
      M Offline
      moffa13
      wrote on 20 Sept 2018, 14:06 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.

      M 1 Reply Last reply 20 Sept 2018, 14:25
      0
      • M moffa13
        20 Sept 2018, 14:06

        @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.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 20 Sept 2018, 14:25 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.

        M 1 Reply Last reply 20 Sept 2018, 15:13
        0
        • M mrjj
          20 Sept 2018, 14:25

          @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.

          M Offline
          M Offline
          moffa13
          wrote on 20 Sept 2018, 15:13 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

          M 1 Reply Last reply 20 Sept 2018, 15:19
          0
          • M moffa13
            20 Sept 2018, 15:13

            @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

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 20 Sept 2018, 15:19 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
            • M Offline
              M Offline
              moffa13
              wrote on 20 Sept 2018, 15:30 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.

              M 1 Reply Last reply 20 Sept 2018, 15:44
              0
              • M moffa13
                20 Sept 2018, 15:30

                @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.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 20 Sept 2018, 15:44 last edited by
                #12

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

                M 1 Reply Last reply 20 Sept 2018, 16:31
                0
                • M mrjj
                  20 Sept 2018, 15:44

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

                  M Offline
                  M Offline
                  moffa13
                  wrote on 20 Sept 2018, 16:31 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.

                  M 1 Reply Last reply 20 Sept 2018, 16:36
                  0
                  • M moffa13
                    20 Sept 2018, 16:31

                    @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.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 20 Sept 2018, 16:36 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
                    • M Offline
                      M Offline
                      moffa13
                      wrote on 21 Sept 2018, 10:31 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

                      15/15

                      21 Sept 2018, 10:31

                      • Login

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